[Numpy-discussion] Variable in an array name?
dstaley at usgs.gov
Wed Jan 12 10:40:51 EST 2011
Zachary Pincus-2 wrote:
>> Is it possible to use a variable in an array name? I am looping
>> through a
>> bunch of calculations, and need to have each array as a separate
>> I'm pretty new to python and numpy, so forgive my ignorance. I'm
>> sure there
>> is a simple answer, but I can't seem to find it.
>> let's say i have a variable 'i':
>> i = 5
>> I would like my array to have the name array5
>> I know how I could do this manually, but not in a loop where i is
>> several times.
> There are ways to do this, but what you likely actually want is just
> to put several arrays in a python list and then index into the list,
> instead of constructing numbered names.
> array_list = 
> for whatever:
> for array in array_list:
> given_array = array_list[i]
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
Thank you very much for the prompt response. I have already done what you
have suggested, but there are a few cases where I do need to have an array
named with a variable (looping through large numbers of unrelated files and
calculations that need to be dumped into different analyses). It would be
extraordinarily helpful if someone could post a solution to this problem,
regardless of inefficiency of the method. Thanks a ton for any additional
View this message in context: http://old.nabble.com/Variable-in-an-array-name--tp30645276p30654306.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion