[Numpy-discussion] reshape and ravel methods of arrays now return views or raise error

Travis Oliphant oliphant.travis at ieee.org
Tue Mar 28 22:03:02 EST 2006


Zachary Pincus wrote:
>>> Unfortunately, the ravel/reshape methods seem to not be quite worked 
>>> out properly yet. Basically (and as expected) the ravel method 
>>> doesn't work anymore on fortran-strided arrays. But since 
>>> fortran-strided arrays happen *all-the-time* (e.g. after a transpose 
>>> operation), things get confusing fast.
>>>
>
>
> One question: was the issue in my example code where fortran-strided 
> arrays couldn't be reshaped at all a feature or a bug in the reshape 
> method?
It's now a feature.  Reshape will only work if it can produce a view of 
the array.  Actually, I can't claim that I've thoroughly analyzed every 
possibility to determine if a view is possible.  I'm sure there are 
cases where a view is technically feasible. The simple rules are:

1) If you are only adding or deleting ones from the shape, then it 
always succeeds.
2) If you aren't actually changing the shape it always succeeds (a -1 
present means you are changing the
shape)

Other than that it only succeeds if you are reshaping a C-contiguous 
array using C-ordering or you are reshaping a Fortran-contiguous array 
using Fortran-ordering.

-Travis





More information about the NumPy-Discussion mailing list