loop through arrays and find maximum

questions anon questions.anon at gmail.com
Mon Dec 5 17:32:35 EST 2011


I would like to calculate the max and min across many netcdf files.
I know how to create one big array and then concatenate and find the
numpy.max but when I run this on 1000's of arrays I have a memory error.
What I would prefer is to loop through the arrays and produce the maximum
without having the make a big array.
Does anyone have any ideas as to how I could achieve this?
My idea goes something like:

netCDF_list=[]
maxarray=[]

for dir in glob.glob(MainFolder + '*/01/')+ glob.glob(MainFolder +
'*/02/')+ glob.glob(MainFolder + '*/12/'):
        for ncfile in glob.glob(dir + '*.nc'):
            netCDF_list.append(ncfile)
for filename in netCDF_list:
        ncfile=netCDF4.Dataset(
filename)
        TSFC=ncfile.variables['T_SFC'][:]
        fillvalue=ncfile.variables['T_SFC']._FillValue
        TSFC=MA.masked_values(TSFC, fillvalue)
        for i in TSFC:
                if i == N.max(TSFC, axis=0):
                        maxarray.append(i)
                else:
                        pass

print maxarray
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111206/5e934082/attachment-0001.html>


More information about the Python-list mailing list