[Numpy-discussion] question about a data structure

Ernest Adrogué eadrogue@gmx....
Thu Jul 30 14:40:03 CDT 2009


29/07/09 @ 14:54 (-0700), thus spake Christopher Barker:
> Robert Kern wrote:
> > 2009/7/29 Ernest Adrogué <eadrogue@gmx.net>:
> >> Now, I need to be able to differentiate between 0 and 'no data'.
> 
> >> Is it possible to do this with the standard array class?
> > 
> > Not really. Use masked arrays. Or use a dictionary.
> 
> masked arrays are made precisely for this. However, if you can use 
> floating point numbers, you could use NaN for the no data entries.

Thanks for the advice. Actually, I think I'll use a combination of
a dictionary and a masked array. I have been playing around a bit
and it doesn't seem too difficult to do. It works by adding an extra
property to the array objects, which is a tuple with the "keys", and
then use the __getitem__ and __setitem__ methods to translate the
keys into numbers. This way it's possible to use strings in
subscripts and slices.

Ernest


More information about the NumPy-Discussion mailing list