[Numpy-discussion] buggy fortran array reshape ?

Fabrice Pardo Fabrice.Pardo@Lpn.cnrs...
Wed Apr 22 13:18:14 CDT 2009


josef.pktd@gmail.com wrote:
>
> 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.
>   
You are right, the documentation doesn't lies.

The simplistic current version choice is a copy.
In my example, b is 1D, contiguous, with no 'C' or 'F' difference.
Then that's possible to do an other choice, making a view.

The reshape function is unpredictable and its behaviour is not documented.

It cannot be used safely.

Another remark against reshape:
OWNDATA flag is False, even if b is a copy !

-- 
FP







More information about the Numpy-discussion mailing list