[Numpy-discussion] Inplace reshape

Anne Archibald peridot.faceted@gmail....
Mon Apr 23 12:20:18 CDT 2007


On 23/04/07, Gael Varoquaux <gael.varoquaux@normalesup.org> wrote:
> Hi,
>
> I thought I remembered there was a way to reshape in-place an array, but
> neither google, nor greping my mailbox brings anything out.
> Am I wrong, or is there indeed a way to reshape in-place an array ?

Sometimes it's just impossible to reshape an array without copying.
But reshape()  (either the method or the function) copies only the
array descriptor if that's possible. So you'll have a new ndarray
object, but the data will not be copied. Assigning to the shape
attribute might do what you want (if it triggers a reshape()
internally, which I think it does).

I don't think it's possible to *rearrange* the data in memory in
place. I can't even think of an algorithm to do that, off the top of
my head.

Anne


More information about the Numpy-discussion mailing list