[Numpy-discussion] ndarray newbie question

Vincent Nijs v-nijs at kellogg.northwestern.edu
Thu Jan 4 13:40:08 CST 2007


--b,

The only data type in python that has a keys() method is a dictionary.
Unless it is a record array (http://www.scipy.org/RecordArrays) there is no
information on variable names contained in the object. However, even record
arrays don't have a keys() method.

Vincent





On 1/4/07 1:18 PM, "belinda thom" <bthom at cs.hmc.edu> wrote:

> Hello,
> 
> I wrote a "display obj" method for viewing instance data:
> 
> def dobj(obj) :
>      """extended object viewer that displays arg"""
>      print 'Class: ', obj.__class__.__name__, ' id:', id(obj)
>      for k in obj.__dict__.keys() :
>          print '  ', k, ': ', obj.__dict__[k], ' id:', id(obj.__dict__
> [k])
> 
> 
> and I'm wondering why it doesn't work on ndarrays:
> 
>>>> m = numpy.zeros(3)
>>>> dobj(m)
> 
> complains because:
> 
> AttributeError: 'numpy.ndarray' object has no attribute '__dict__'
> 
> I am also fairly new to python, but would have thought all objects
> had dictionaries, especially when they are comprised of other things,
> e.g.
> 
> dir(m)
> 
> produces a slew of components, e.g.
> 
> tofile, ..., transpose, ..., view, etc.
> 
> Thanks for any insight.
> 
> --b
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
> 




More information about the Numpy-discussion mailing list