[Numpy-discussion] buggy fortran array reshape ?
Wed Apr 22 12:51:45 CDT 2009
On Wed, Apr 22, 2009 at 1:13 PM, Fabrice Pardo
> 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 ?
> 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
> check_bug('C') # 2, good
> check_bug('F') # 1, wrong ???
> print(numpy.version.version) # 1.2.1
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.
More information about the Numpy-discussion