[SciPy-User] Remove the need for the loop
Martin De Kauwe
Mon Mar 22 20:05:28 CDT 2010
I would like to transfer the contents of a 1D array to a 2D array based on
two arrays listing the relevant locations (the arrays rows and cols).
Ideally I would like to solve my problem without the need for the current
for loop that it quite slow due to the array size. Any help doing this more
elegantly would be much appreciated.
What I currently have...
for fname in glob.glob(os.path.join(path, 'Snowf_P3_*.nc')):
year = int(fname.split('/').split('_').split('.')[0:4])
if year >= year_jules_run_starts and year <= year_jules_run_ends:
month = int(fname.split('/').split('_').split('.')[4:6])
f = Dataset(fname, 'r')
snow = f.variables['Snowf']
landpts = len(f.dimensions['land'])
# sum monthly vals
gswp_snow = (snow[:] * 1000.0 * (3.0 * 60.0 * 60.0) /
# fill up the holding array, this is the bit where I would like to
avoid the for loop
for point in xrange(numpts):
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User