
The PEP says:
Iterator
An iterator will be defined that will walk through any array, returning a rank-0 array at each step. Rank-0 arrays act like the appropriate Python scalar and will be converted to one whenever Python asks the object explicitly to try and do so. Order of the iteration is the same for contiguous and discontiguous arrays. The last index always varies the fastest
At the moment, iteration over a rank-N array yields rank-(N-1) arrays (indexing along the first dimension). I consider this vastly more useful than iterating over the rank-0 elements and thus ignoring the array structure completely.
Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Laboratoire Léon Brillouin, CEA Saclay, 91191 Gif-sur-Yvette Cedex, France Tel.: +33-1 69 08 79 25 Fax: +33-1 69 08 82 61 E-Mail: hinsen@llb.saclay.cea.fr ---------------------------------------------------------------------

Quoting konrad.hinsen@laposte.net:
At the moment, iteration over a rank-N array yields rank-(N-1) arrays (indexing along the first dimension). I consider this vastly more useful than iterating over the rank-0 elements and thus ignoring the array structure completely.
Completely agreed. I'm sure I'm not the only one who has code like
for row in matrix: do_something_with(row)
Furthermore, this is consistent with python's behavior for nested lists:
In [3]: nested=[['first row',1,2],['second row',3,4]]
In [4]: for row in nested: ...: print row ...: ['first row', 1, 2] ['second row', 3, 4]
Python does not flatten nested structures when iterating over them, neither should numerix. I think the addition (which Travis seems keen on) the .flat iterator attribute is the right approach here. Normal iterators would maintain structure (and behave like pyhon's for nested lists), while .flat would return an element-wise iterator for cases where such a thing is needed (which do exist, obviously).
Regards,
f
participants (3)
-
Fernando.Perez@colorado.edu
-
konrad.hinsen@laposte.net
-
Stephen Walton