Psycho
Psycho

Reputation: 23

Creating 2d array and filling first columns of each row in numpy

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)

Upvotes: 2

Views: 241

Answers (1)

swag2198
swag2198

Reputation: 2696

Simply do this:

y[:, 0] = np.sin(PI*x/L)

Upvotes: 2

Related Questions