[Numpy-discussion] Response to PEP suggestions
Fernando.Perez at colorado.edu
Thu Feb 17 14:06:11 EST 2005
David M. Cooke wrote:
> Right now, I find X.flat to be pretty useless, as you need a
> contiguous array. I'm +1 on making X.flat work in all cases (contiguous
> and discontiguous). Either
> a) X.flat returns a contiguous 1-dimensional array (like ravel(X)),
> which may be a copy of X
> b) X.flat returns a "flat-indexable" view of X
> I'd argue for b), as I feel that attributes should operate as views,
> not as potential copies. To me, attributes "feel like" they do no
> work, so making a copy by mere dereferencing would be suprising.
+1 on b).
I have quite a bit of code doing things like
which feels silly. It would be nice for .flat to be a guaranteed, indexable,
no-copy view of the original (even if it's non-contiguous). Granted, the
indexing will be costlier for a non-contiguous object, but for the external
users this provides a clean API.
More information about the NumPy-Discussion