[Numpy-discussion] numarray.records - get/set item
haase at msg.ucsf.edu
Fri Jan 16 16:02:01 CST 2004
I would like to check if there has been made a decision on this ?
I'm planning to use record arrays to access image data header-information
and having an attribute 'f' like suggested is still my favorite way.
Is anyone besides me using record arrays on memory-mapped buffers ?
----- Original Message -----
From: "Sebastian Haase" <haase at msg.ucsf.edu>
To: <numpy-discussion at lists.sourceforge.net>
Sent: Thursday, December 04, 2003 4:27 PM
Subject: Fw: [Numpy-discussion] numarray.records - get/set item
> My situation where I got onto this, is having one field named 'mmm'
> ("MinMaxMean") being an 3 element array.
> Now, to assign the values first I tried:
> self.hdrArray = makeHdrArray(self.h) #this makes the record array
> self.hdr = self.hdrArray.field #this is my shortcut to the
> bound member function
> # it essentially is a solution (hack) for the getitem part
> # but regarding setitem I had to learn that "assigning to a function"
> illigal in Python - as opposed to C++
> #so to do assignment I need to do:
> self.hdr('mmm'), self.hdr('mmm'), self.hdr('mmm') = (mi,ma,av)
> now that I'm looking at it,
> self.hdrArray.setfield('mmm', (mi,ma,av))
> would probably be better...
> How about adding an attribute 'f' which could serve as a "proxy" to allow:
> myRec.f.mmm = (mi,ma,av)
> and maybe even additionally:
> myRec.f['mmm'] = (mi,ma,av)
> ----- Original Message -----
> From: "Perry Greenfield" <perry at stsci.edu>
> To: "Sebastian Haase" <haase at msg.ucsf.edu>;
> <numpy-discussion at lists.sourceforge.net>
> Sent: Thursday, December 04, 2003 3:08 PM
> Subject: RE: [Numpy-discussion] numarray.records - get/set item
> > > Hi,
> > > Is it maybe a good idea to add this to the definition of 'class
> > >
> > > class Record:
> > > """Class for one single row."""
> > > <snip>
> > > def __getitem__(self, fieldName):
> > > return self.array.field(fieldName)[self.row]
> > > def __setitem__(self, fieldName, value):
> > > self.array.field(fieldName)[self.row] = value
> > >
> > > I don't know about the implications if __delitem __ and so on are
> > > defined.
> > > I just think it would look quite nice to say
> > > myRecArr['mmm'] = 'hallo'
> > > as opposed to
> > > myRecArr.setfield('mmm', 'hallo')
> > >
> > > Actually I would even like
> > > myRecArr.mmm = 'hallo'
> > >
> > > This should be possible by defining __setattr__.
> > > It would obviously only work for fieldnames that do not contain '.' or
> > > or ...
> > >
> > > Any comments ?
> > >
> > >
> > We've had many internal discussions about doing this. The latter was
> > considered a problem because of possible name collisions of field
> > names with other attributes or methods. The former is not bothered
> > by this problem, but we decided to be conservative on this and see
> > how strong the need was. We are interested in other opinions.
> > Perry
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
More information about the Numpy-discussion