[Numpy-discussion] Change default order to Fortran order

Sebastian Berg sebastian at sipsolutions.net
Mon Aug 3 10:53:23 EDT 2015


On Mon Aug 3 16:26:10 2015 GMT+0200, Matthew Brett wrote:
> Hi,
> 
> On Mon, Aug 3, 2015 at 3:13 PM, Gregory Lee <grlee77 at gmail.com> wrote:
> > I agree that often you don't need to worry about the memory order.  However,
> > it is not uncommon in medical imaging to go back and forth between a 2D or
> > 3D image representation and a 1D array representation (e.g. as often used in
> > image reconstruction algorithms).  I found that the main time it was
> > necessary to pay careful attention to the memory layout was when converting
> > Matlab scripts that involve reshaping operations.
> 
> Yes, good point.    A typical example would be this kind of thing:
> 
> # data is a 4D array with time / volume axis last
> data_2d = data.reshape((-1, data.shape[-1])
> 
> For MATLAB, the columns of this array would (by default) have the
> values on the first axis fastest changing, then the second, then the
> third, whereas numpy's default is the other way round.
> 
> I find I usually don't have to worry about this, because I'm later going to do:
> 
> data_processed_4d  = data_2d.reshape(data.shape)
> 
> which will reverse the previous reshape in the correct way.
> 
> But in any case - this is not directly to do with the array memory
> layout.  You will get the same output from reshape whether the memory
> layout of `data` was Fortran or C.
>

Just as a remark. Reshape has an (iteration not really memory) order parameter, thou it may do more copies if those do not match.

- Sebastian
 
> Cheers,
> 
> Matthew
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
>


More information about the NumPy-Discussion mailing list