[Numpy-discussion] numpy.array(arr.flat) mutates arr if arr.flags.fortran: bug?

Charles R Harris charlesr.harris at gmail.com
Fri Mar 26 11:26:05 EDT 2010


On Wed, Mar 24, 2010 at 1:13 PM, Zachary Pincus <zachary.pincus at yale.edu>wrote:

> Hello,
>
> I assume it is a bug that calling numpy.array() on a flatiter of a
> fortran-strided array that owns its own data causes that array to be
> rearranged somehow?
>
> Not sure what happens with a fancier-strided array that also owns its
> own data (because I'm not sure how to create one of those in python).
>
> This is from the latest svn version (2.0.0.dev8302) but was also
> present in a previous version too.
>
> Zach
>
>
> In [9]: a = numpy.array([[1,2],[3,4]]).copy('F')
>
> In [10]: a
> Out[10]:
> array([[1, 2],
>        [3, 4]])
>
> In [11]: list(a.flat)
> Out[11]: [1, 2, 3, 4]
>
> In [12]: a # no problem
> Out[12]:
> array([[1, 2],
>        [3, 4]])
>
> In [13]: numpy.array(a.flat)
> Out[13]: array([1, 2, 3, 4])
>
> In [14]: a # this ain't right!
> Out[14]:
> array([[1, 3],
>        [2, 4]])
>
> In [15]: a = numpy.array([[1,2],[3,4]]).copy('C')
>
> In [16]: numpy.array(a.flat)
> Out[16]: array([1, 2, 3, 4])
>
> In [17]: a
> Out[17]:
> array([[1, 2],
>        [3, 4]])
>
>
You should open a ticket for this.

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


More information about the NumPy-Discussion mailing list