[Numpy-discussion] storage order and concatenate

David Cournapeau david at ar.media.kyoto-u.ac.jp
Thu Sep 28 04:44:21 CDT 2006


    I noticed a behaviour which I found counter-intuitive at least when 
using concatenate. I have a function which takes a numpy array of rank 2 
as input, let's say foo(in):

a    = N.randn((10, 2))

To test a ctype implementation of foo against the python version, my 
test has something like

X1  = N.linspace(-2, 2, 10)[:, N.newaxis]
X2  = N.linspace(-1, 3, 10)[:, N.newaxis]
a    = N.concatenate(([X1, X2]), 1)

which has Fortran storage (column major order), where as creating a as

a       = N.zeros((10, 2))
a[:,0] = N.linspace(-2, 2, 10)
a[:,1] = N.linspace(-1, 3, 10)

has C storage (row major order).

What are the rules concerning storage with numpy ? I thought it was 
always C, except if stated explicitly. I can obviously understand why 
concatenate gives a Fortran order from an implementation point of view, 
but this looks kind of strange to me,


More information about the Numpy-discussion mailing list