[Numpy-discussion] Creating and reshaping fortran order arrays

Matthew Brett matthew.brett at gmail.com
Mon Aug 14 12:23:07 CDT 2006


Hi,

I am sorry if this is obvious, but:

I am working on the scipy loadmat module, and would like to use numpy
to reformat the fortran order arrays that matlab saves.  I was not
sure how to do this, and would like to ask for advice.

Let us say that I have some raw binary data as a string.  The data
contains 4 integers, for a 2x2 array, stored in fortran order.

For example, here is 0,1,2,3 as int32

str = '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'

What is the best way of me putting this into a 2x2 array object so
that the array recognizes the data is in fortran order.  Sort of:

a = somefunction(str, shape=(2,2), dtype=int32, order='F')

such that a.shape = (2,2) and a[1,0] == 1, rather than 2.

Sorry if that's obvious, but I couldn't see it immediately....

Thanks a lot,

Matthew




More information about the Numpy-discussion mailing list