[Numpy-discussion] Fortran ordering

Paul Northug pnorthug at gmail.com
Fri Apr 16 15:35:23 EDT 2010


I'd like to use numpy fortran ordering in order to use some external
libraries more easily, but it looks like I don't understand how it
works and it is causing transposes that are confusing me.

When I define an array as:

a = np.array([[1.,2.],[3.,4.]], order='F', type=np.float32)

how is it stored in memory, as [1, 2, 3, 4] or [1, 3, 2, 4]?

a.strides == (4, 8), suggesting [1, 3, 2, 4]. I can also check by
stepping through:

ap = a.ctypes.data_as(POINTER(c_float))
ap[:4]  == [1., 3., 2., 4.]

But when I call external libraries through ctypes with a.ctypes.data
as argument, the external function gets [1, 2, 3, 4] (I think).
Eventually, I plan to use cython's buffer interface and a.data. Will
it be [1, 2, 3, 4] there as well? Or is my external code broken.

I am glad that numpy hides ordering issues to the extent that it does
as it prevents my code from exploding. But I would like to get around
this one particular case, so if someone can explain what is going on
underneath, I would appreciate it.



More information about the NumPy-Discussion mailing list