[Numpy-discussion] numpy.array(arr.flat) mutates arr if arr.flags.fortran: bug?
Zachary Pincus
zachary.pincus@yale....
Wed Mar 24 14:13:04 CDT 2010
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]])
More information about the NumPy-Discussion
mailing list