[Numpy-discussion] reshape and ravel methods of arrays now return views or raise error
oliphant.travis at ieee.org
Tue Mar 28 18:20:03 CST 2006
Zachary Pincus wrote:
> Uh oh,
> Just updated to new numpy so that dot() wouldn't be broken. What fun
> to play with the new order/ravel/reshape stuff.
> 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.
You've demonstrated my biggest concern with adopting Tim's approach.
Because you can very easily get arrays that are not C-contiguous, you
end up with a stituation in which the reshape and ravel methods are not
very useful in my mind.
> In fact, absolutely no reshape operation (other than the identity
> reshape) will work on fortran-strided arrays (see below). Also, the
> errors could be more helpful, and anyway ravel shouldn't fail with an
> error about reshape fortran-strided.
There is one more problem with what I checked in. The PyArray_Ravel()
function in C is now completely different and is used in _check_axis and
therefore creates a segfault.
So, I've decided to compromise.
.reshape maintains it's view-only behavior
.ravel() goes back to copy-if-necessary behavior (If you don't like it
then use .reshape(-1) ).
This should fix most of Zach's concerns and also fixes the segfault you
More information about the Numpy-discussion