[Numpy-discussion] buggy fortran array reshape ?

josef.pktd@gmai... josef.pktd@gmai...
Wed Apr 22 14:12:20 CDT 2009

On Wed, Apr 22, 2009 at 2:37 PM, Pauli Virtanen <pav@iki.fi> wrote:
> Wed, 22 Apr 2009 20:18:14 +0200, Fabrice Pardo wrote:
> [clip]
>> The reshape function is unpredictable and its behaviour is not
>> documented.
>> It cannot be used safely.
> It is documented and it can be used safely. The manual, however, has
> currently no section on views that would explain these issues in depth.
> If you want to ensure no-copy, assign to shape:
> a.shape = (6,)
>> Another remark against reshape:
>> OWNDATA flag is False, even if b is a copy !
> Apparently, reshape first copies to a contiguous array and then reshapes.
> This could be simplified.

Is the difference between assigning to the attribute and using the
method call explained

I had recently the puzzling case, where I wanted to create a
structured array, and tried

x.dtype = ...

I don't remember exactly, but view and astype didn't create the
structured array that I wanted,
while the assignment x.dtype = ...  worked.

>This has the effect that the unravelling is done in Fortran order (when
>order='F') rather than C-order, which can be confusing at times.

If he intentionally starts out in Fortran order, he might have a
reason to stick to it.
In stats, we are still focused by default on axis=0, and I usually
think in terms of columns of random variables. But using a lot of
transpose and newaxis, I never know what the memory layout is unless I
check the flags, and I'm starting to realize that this requires more
attention with numpy.


More information about the Numpy-discussion mailing list