[Numpy-discussion] very simple iteration question.
Wed Apr 30 13:57:44 CDT 2008
Anne Archibald wrote:
>> it's much easier to just write
> for subarray in np.rollaxis(A,i):
cool, thanks! So the answer to the OPs question:
> OK: how do i iterate over an axis other than 0?
> I have a 3D array of data[year, week, location]. I want to iterate
> over each year at each location ...
for loc in np.rollaxis(data, 2):
for year in np.rollaxis(data, 0): # rollaxis not required here, but
# for symmetry's sake...
I think I still like the idea of an iterator (or maybe making rollaxis a
method?), but this works pretty well.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the Numpy-discussion