[Numpy-discussion] fortran array storage question
Fri Oct 26 07:25:44 CDT 2007
Georg Holzmann wrote:
> I found now a way to get the data:
>> Therefore I do the following (2D example):
>> obj = PyArray_FromDimsAndData(2, dim0, PyArray_DOUBLE, (char*)data);
>> PyArrayObject *tmp = (PyArrayObject*)obj;
>> tmp->flags = NPY_FARRAY;
> if in that example I also change the strides:
> int s = tmp->strides;
> tmp->strides = s;
> tmp->strides = s * dim0;
> Then I get in python the fortran-style array in right order.
> However, I don't know if this is the usual way or if it has a
> performance overhead ...
This depends on what you are trying to do, but generally, I find that if
you can afford it memory-wise, it is much faster to just get a C
contiguous array if you treat your C array element per element. If you
don't access element per element, then it can become much more
difficult, of course (specially if you have to use several times the
same parts of the memory).
More information about the Numpy-discussion