[Numpy-discussion] iterate over multiple arrays
David Froger
david.froger at gmail.com
Tue Sep 13 02:53:48 EDT 2011
Thank you Olivier and Robert for your replies!
Some remarks about the dictionnary solution:
from numpy import *
def f(arr):
return arr + 100.
arrs = {}
arrs['a'] = array( [1,1,1] )
arrs['b'] = array( [2,2,2] )
arrs['c'] = array( [3,3,3] )
arrs['d'] = array( [4,4,4] )
for key,value in arrs.iteritems():
arrs[key] = f(value)
1. about the memory
Memory is first allocated with the array functions:
arrs['a'] = array( [1,1,1] )
arrs['b'] = array( [2,2,2] )
arrs['c'] = array( [3,3,3] )
arrs['d'] = array( [4,4,4] )
Are there others memory allocations with this assignemnt:
arrs[key] = f(value)
or is the already allocated memory used to store the result of f(value)?
In other words, if I have N arrays of the same shape, each of them costing
nbytes of memory, does it use N*nbytes memory, or 2*N*bytes?
I think this is well documented on the web and I can find it....
2. about individual array
The problem is that now, if one want to use a individual array, one have now to
use:
arrs['a']
instead of just:
a
So I'm sometime tempted to use locals() instead of arrs...
--
More information about the NumPy-Discussion
mailing list