In such a situation you should probably use a dictionary from the start, i.e.:<br>   d3['index'] = np.arange(100)<br>then use d3['index'] everywhere instead of index.<br><br>It can be more convenient (notation-wise) to use an object instead, i.e. either work within a class method (self.index = np.arange(100)), or use a class as storage instead of a dictionary:<br>
<br>class ArrayHolder(object):<br>    pass<br><br>a = ArrayHolder()<br><br>a.index = np.arange(100)<br>...<br>d3 = a.__dict__.copy()<br><br>Finally, another option I can see is to use a custom class that holds both a numpy array and a name. Maybe with a convenient accessor to the array through the call method:<br>
<br>class NamedArray(object):<br><br>    def __init__(self, array, name):<br>        self.array = array<br>        <a href="http://self.name">self.name</a> = name<br><br>    def __call__(self):<br>        return self.array<br>
<br>index = NamedArray(numpy.arange(100), 'index')<br>...   # use index() in the rest of the code whenever you want the numpy array<br>d3[<a href="http://index.name">index.name</a>] = index()<br><br>-=- Olivier<br>
<br><div class="gmail_quote">2011/11/10 Chao YUE <span dir="ltr"><<a href="mailto:chaoyuejoy@gmail.com">chaoyuejoy@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi, <br><br>Does anyone know how I can quickly use the name of a ndarray as a string?<br>for example, I have<br>In [54]: index=np.arange(100)<br><br>then I want to use the name 'index' as a key in a new dictionary:<br>

d3=dict()<br>d3['index']=index<br><br>I can do it like the way above, but I have many ndarray variables that need to be included in the dictionary.<br>is there something like:<br>d3[<a href="http://index.name" target="_blank">index.name</a>()]=index <br>

while <a href="http://index.name" target="_blank">index.name</a>() would equal the string 'index'?<br><br>I hope my question is clear. thanks to all.<br><br>Chao<br><font color="#888888">-- <br><div>***********************************************************************************</div>


<div>Chao YUE<br>Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>UMR 1572 CEA-CNRS-UVSQ<br>Batiment 712 - Pe 119<br>91191 GIF Sur YVETTE Cedex</div>
<div>Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br></div>

<div>************************************************************************************</div><br>
</font><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>