[Numpy-discussion] Fortran ordering

Stéfan van der Walt stefan at sun.ac.za
Sat Apr 17 13:50:22 EDT 2010


On 16 April 2010 21:35, Paul Northug <pnorthug at gmail.com> wrote:
> how is it stored in memory, as [1, 2, 3, 4] or [1, 3, 2, 4]?

The latter:

In [22]: np.fromstring(str(x.data))
Out[22]: array([ 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).

That should not be the case.  Please see the attached code as a
demonstration, which has the following output:

Printing values as in memory:
1 3 2 4
Let's assign values 0, 1, 2 and 3 to consecutive memory
addresses.  The result is:
[[ 0.  2.]
 [ 1.  3.]]

Regards
Stéfan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bytes_.c
Type: application/octet-stream
Size: 259 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100417/cf45ac8c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fortran_test.py
Type: text/x-python-script
Size: 775 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100417/cf45ac8c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SConstruct
Type: application/octet-stream
Size: 116 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100417/cf45ac8c/attachment-0001.obj>


More information about the NumPy-Discussion mailing list