[Numpy-discussion] buggy fortran array reshape ?
josef.pktd at gmail.com
josef.pktd at gmail.com
Wed Apr 22 13:51:45 EDT 2009
On Wed, Apr 22, 2009 at 1:13 PM, Fabrice Pardo
<Fabrice.Pardo at lpn.cnrs.fr> wrote:
>
> After reshaping a Fortran array, the new array doesn't share data
> with original array.
> I will be glad if someone can explain the strange behaviour of this
> program. Is it a numpy bug ?
>
> #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> def check_bug(order):
> a = numpy.ndarray((3,2),order=order,dtype=int)
> a[0,0] = 1
> b = a.reshape((6,))
> a[0,0] = 2
> print b[0]
>
> check_bug('C') # 2, good
> check_bug('F') # 1, wrong ???
> print(numpy.version.version) # 1.2.1
> #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
from help:
"""
Returns:
reshaped_array : ndarray
This will be a new view object if possible; otherwise, it will be a copy.
"""
" if possible" and "otherwise" are not very precise
I guess reshape tries to return an array that is contiguous, if you do
a reshape in the order of the array, i.e.
change your line to
b = a.reshape((6,), order=order)
then the reshaped array is just a view.
I still find view vs copy very confusing.
Josef
More information about the NumPy-Discussion
mailing list