[Numpy-discussion] flatten() without copy - is this possible?

Andrew Jaffe a.h.jaffe at bakerjaffe.plus.com
Mon Jun 4 10:17:00 EDT 2007


dmitrey wrote:
> hi all.
> in the numpy for matlab users I read
> 
> y = x.flatten(1)
> 
> turn array into vector (note that this forces a copy)
> 
> Is there any way to do the trick wthout copying?
> What are the problems here? Just other way of array elements indexing...

One important question is whether you actually need the new vector, or 
whether you just want a flat index into the array; if the latter, you 
can always [I think] use x.flat[one_d_index]. (But note that y=x.flat 
gives an iterator, not a new array.)

Andrew




More information about the NumPy-Discussion mailing list