[Numpy-discussion] New arrays in 1.6 not always C-contiguous

Charles R Harris charlesr.harris at gmail.com
Thu Jul 7 09:52:39 EDT 2011


On Thu, Jul 7, 2011 at 7:24 AM, Yoshi Rokuko <yoshi at rokuko.net> wrote:

> thank you for pointing that out!
>
> so how do you change your numpy related c code now, would you like to
> share?
>
>
Either you have to deal with the axes in the c-code -- cython is an option
there -- or you can check and make a copy of the array to be sure that it is
both contiguous and in c-order.

In [18]: a = np.ones((2,2))

In [19]: a.strides
Out[19]: (16, 8)

In [20]: a.T.strides
Out[20]: (8, 16)

In [21]: ascontiguousarray(a.T).strides
Out[21]: (16, 8)

Strictly speaking, you should have been doing that anyway, but sometimes
quick and dirty gets the job done ;)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110707/37bfd8ca/attachment.html>


More information about the NumPy-Discussion mailing list