reshape and keep x,y,z ordering
michael.selik at gmail.com
Tue Jun 7 09:16:37 EDT 2016
On Tue, Jun 7, 2016 at 7:31 AM Heli <hemla21 at gmail.com> wrote:
> I have a question regarding reshaping numpy array.
> I either have a 1D array that I need to reshape to a 3D array or a 3D
> array to reshape to a 1d numpy array.
> In both of these cases it is assumed that data follows x,y,z ordering.
> and I use the following to reshape the numpy array.
> My question is if there is anyway that reshape would keep x,y,z ordering
> that would not require transpose? and if there is a better more efficient
> way to do this?
>>> a = np.arange(9).reshape(3,3)
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
array([0, 3, 6, 1, 4, 7, 2, 5, 8])
Does this work for you?
The flatten method normally goes row by row, but you can specify FORTRAN
style column by column flattening.
More information about the Python-list