How can I make a Numpy matrix with values in a certain range?

Viewed 78

I know if I do m = np.arange(1, 10), I'll get a matrix with values from 1 to 9 going across the rows. Is there a similar function to do this with values from 1 to 9 that go down the columns? i.e.,

1 4 7
2 5 8
3 6 9
3 Answers

You can use the reshape function from numpy

np.arange(1, 10).reshape(3,3,order='F')

array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])

numpy reshape function can help

m.reshape(3,3, order='F')

Related