[Numpy-discussion] how to avoid re-shaping
Massimo DiPierro
massimo.dipierro at gmail.com
Tue May 22 11:21:26 EDT 2012
On May 22, 2012, at 10:12 AM, Robert Kern wrote:
> On Tue, May 22, 2012 at 4:09 PM, Massimo DiPierro
> <massimo.dipierro at gmail.com> wrote:
>> One more questions (since this list is very useful. ;-)
>>
>> If I have a numpy array of arbitrary shape, is there are a way to sequentially loop over its elements without reshaping it into a 1D array?
>>
>> I am trying to simplify this:
>>
>> n=product(data.shape)
>> oldshape = data.shape
>> newshape = (n,)
>> data.reshape(newshape)
>
> Note that the .reshape() method does not work in-place. It just
> returns a new ndarray object viewing the same data using the different
> shape.
>
> That said, just iterate over data.flat, if you must iterate manually.
That's what I was looking for. Thank you.
> --
> Robert Kern
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list