[Numpy-discussion] Iterate over an array

davide lasagna lasagnadavide@gmail....
Fri Aug 28 12:13:56 CDT 2009


Hi all,
I ve got a 2d array and i want to iterate over its columns in a "pythonic
way".
This is what i have in mind: please consider this snippet:

#################################################
import numpy as np

array = np.random.standard_normal( (10,10) )

for column in array.some_column_method():
      column  = do_something()

#################################################

The trivial way do the for loop is:

#################################################
for i in range(  array.shape[1] ):
      array[:, i] = do_something()
#################################################

Is there any way to do what i think?? Can i obtain "pythonically" a list of
column arrays??

Any help is appreciated.

Cheers..

Davide Lasagna

Dip. Ingegneria Aerospaziale
Politecnico di Torino
Italia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090828/d8ddd820/attachment.html 


More information about the NumPy-Discussion mailing list