2

I have written the following code for creating a 2D array and filing the first element of each row. I am new to numpy. Is there a better way to do this?

y=np.zeros(N*T1).reshape(N,T1)
x = np.linspace(0,L,num = N)

for k in range(0,N):
    y[k][0] = np.sin(PI*x[k]/L)

1 Answer 1

2

Simply do this:

y[:, 0] = np.sin(PI*x/L)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.