[Numpy-discussion] recarray field names

Erin Sheldon esheldon at kicp.uchicago.edu
Mon Jul 10 22:54:59 CDT 2006

Just tested the lastest SVN and it works as advertised.  Thanks

An unrelated question: why does this work for arrays but not recarrays?

In [24]: mydescriptor = [('age',float64),('Nchildren',int8),('weight',float32)]   

In [25]: a = array([(64,2,75.0),(25,0,60.0)], dtype=mydescriptor)

In [26]: a = recarray([(64,2,75.0),(25,0,60.0)], dtype=mydescriptor)
exceptions.TypeError                                 Traceback (most recent
call last)

/Users/esheldon/<ipython console> 

TypeError: __new__() got an unexpected keyword argument 'dtype'

I understand that I could use the formats and names keywords, but
this seems a little inconsistent.  


On 7/10/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> John Parejko wrote:
> >Howdy!  I just wanted to voice my agreement with this statment by Erin
> >Sheldon:
> >
> > > I brought up the issue a while back of having a simple way to
> > > access the field names of an array. The quick summary: accessing
> > > field names has some oddness that needs cleaning up.
> >
> >Sometimes a['name'], sometimes a.field('name').  I vastly prefer the first
> >version; it has become my favored way of dealing with my FITS and ASCII
> >data.  But using the bracket notation sometimes gives an error, and I
> >haven't quite figured out what the circumstances are.
> >
> >
> Bracketed version should never give an error.  If you see it, it's a bug.
> >Also, "for name in a.dtype.fields:" or "for name in a.fields:" would be
> >very, very handy.
> >
> >
> You can do this, now  but each key in the fields dictionary might not be
> unique because titles will also be keys in the dictionary.
> A unique list of ordered names can now (in NumPy SVN) be obtained using
> for name in a.dtype.names
> -Travis
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion

More information about the Numpy-discussion mailing list