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

Viewed 44

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 Answers

Simply do this:

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