[Numpy-discussion] how to use the name of a ndarray as a string

Chris.Barker Chris.Barker at noaa.gov
Mon Nov 14 12:26:04 EST 2011

On 11/10/11 3:57 AM, Olivier Delalleau wrote:
> In such a situation you should probably use a dictionary from the start,

all good suggestions, but while we're at it:

On 11/10/11 2:17 AM, Chao YUE wrote:
> Does anyone know how I can quickly use the name of a ndarray as a string?

This reflects a key misunderstanding of how Python works -- a ndarray ( 
or any python object) does not "have a name".

when you write:


you are creating a ndarray object, and _binding_ the name "index" to it. 
the object exists apart from it's name:

l =[]


now there is a an andarray object in the list -- but it has no name. You 
can also bind multiple names to the same object:

fred = index
john = index

now "index", "fred", and "john" are all bound to the same object -- what 
would be its name now?

Hence Olivier's suggestionss -- al various ways to store and refere to 
objects -- binding to a variable is only one way.

This is a good read that should clarify it all:



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the NumPy-Discussion mailing list