[Numpy-discussion] Addition of a dict object to all NumPy objects

Robert Kern robert.kern@gmail....
Fri Aug 15 16:06:40 CDT 2008

On Fri, Aug 15, 2008 at 15:15, Charles R Harris
<charlesr.harris@gmail.com> wrote:
> On Fri, Aug 15, 2008 at 2:10 PM, Charles R Harris
> <charlesr.harris@gmail.com> wrote:
>> On Fri, Aug 15, 2008 at 1:58 PM, Travis E. Oliphant
>> <oliphant@enthought.com> wrote:
>>> Hello all,
>>> While we are on the subject of C-API changes,  I've noticed that quite a
>>> few of the sub-classes of ndarray are constructed to basically add
>>> meta-information to the array.
>>> What if the base-class ndarray grew a dict object at it's end to hold
>>> meta information.
>>> Naturally, several questions arise:
>>> 1) How would you access the dictionary?  (i.e. __dict__?)
>>> 2) Would attribute setting and getting retrieve from this dictionary
>>> (how are conflicts managed).
>>>      * I think I would prefer a dict attribute on the numpy array that
>>> gets and sets into the dictionary.
>>> 3) Are the additional 4-8 bytes too expensive
>> One of the problems with numarray was the time taken to allocate small
>> arrays. Would adding a dictionary slow down the allocation of numpy arrays?
> That said, I think we should keep things as simple and orthogonal as
> possible. If we go this way, I think a subclass with a dictionary would be
> the best approach to avoid the heartbreak of creeping featuritis.

The point of the feature is to avoid subclasses. There are a number of
use cases for annotating arrays with metadata. Currently, they are
forced to use subclasses. Every time you use ndarray subclasses, you
are essentially forcing yourself into your subclass's ghetto of
functions that only work on your subclass.

I think you could make the dictionary created lazily on the first getattr().

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco

More information about the Numpy-discussion mailing list