K.heer K.heer - 4 months ago 15
Python Question

creating array without typing it in explicitly

I want to create 5*3 array like below without typing it explicitly.

[[1, 6, 11],
[2, 7, 12],
[3, 8, 13],
[4, 9, 14],
[5, 10, 15]]


I used write following codes.

np.arange(1, 16).T.reshape((5,3))


but it shows

array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12],
[13, 14, 15]])


How can I order numbers in ascending order so that it becomes the first array?

Answer

That's what you are looking for:

np.arange(1, 16).reshape((3,5)).T
Comments