I have a array like following,
from numpy import * a=array([1,2,3,4,5,6,7,8,9])
I want to get the result like following
[[1,4,7],[2,5,8],[3,6,9]]
Because I have a big array. So i need a efficient way to do it . And it's better to reshape it in-place.
As proposed by @atomh33ls, you can use a reshape passing order='F'
, and "if possible" the returned array will be only a view of the original one, without data being copied, for example:
a=array([1,2,3,4,5,6,7,8,9]) b = a.reshape(3,3, order='F') a[0] = 11 print b #array([[ 1, 4, 7], # [ 2, 5, 8], # [ 3, 6, 9]])
You can use reshape and change the order parameter to FORTRAN (column-major) order:
a.reshape((3,3),order='F')