[Numpy-discussion] subset of array - statistics
Joris De Ridder
Thu Mar 13 21:27:16 CDT 2008
> I am new to the world of Python and numpy
> I have successfully imported the data into lists and then created a
> single array from the lists.
I think putting each quantity in a 1D array is more practical in this
> I can get the rainfall total over the entire period using:
> But what i would like to do is get an average rainfall for each
> month and also
> the ability to get rainfall totals for any month and Year
Assuming that yr, mth and rain are 1D arrays, you may try something
[[average(rain[(yr == y) & (mth == m)]) for m in unique(mth[yr==y])]
for y in unique(yr)]
which gives you the monthly average rainfalls stored in lists, one for
The rain data cannot be reshaped in a 3D numpy array, because not all
months have the same number of days, and not all years have the same
number of months. If they could, numpy would allow you to do something
average(rain.reshape(Nyear, Nmonth, Nday), axis =-1)
to get the same result.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion