[Numpy-discussion] how to avoid re-shaping

Massimo DiPierro massimo.dipierro at gmail.com
Tue May 22 11:09:18 EDT 2012


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)
for i in xrange(n):
     do_something_with(data[i])
data.reshape(oldshape)

Massimo


More information about the NumPy-Discussion mailing list