[Numpy-discussion] BOF notes: Fernando's proposal: NumPy?ndarray with named axes

Lluís xscript at gmx.net
Tue Jul 13 08:31:26 EDT 2010


Ryan May writes:

> On Mon, Jul 12, 2010 at 8:04 AM, Neil Crighton <neilcrighton at gmail.com> wrote:
>> Gael Varoquaux <gael.varoquaux <at> normalesup.org> writes:
>>> I do such manipulation all the time, and keeping track of which axis is
>>> what is fairly tedious and error prone. It would be much nicer to be able
>>> to write:
>>> 
>>>     data.ax_day.mean(axis=0)
>>>     data.ax_hour.mean(axis=0)
>>> 
>> 
>> Thanks, that's a really nice description. Instead of
>> 
>> data.ax_day.mean(axis=0)
>> 
>> I think it would be clearer to do something like
>> 
>> data.mean(axis='day')

> IIRC somewhere, at least at the BOF, this exact syntax was intended to
> be supported.

Yes, this is already implemented on datarray.

Even if the 'axis' argument were not automatically translated from an axis name
to the axis index (i.e., an extension on top of scipy, as the current
datarray implementation patches functions one-by-one), you could still be
getting the index through the name with something similar to:

   arr.mean(axis=arr.axis['day'].index)

Note that this arr.axis['day'] is still not implemented, but I wrote on the wiki
the possibility of providing it (as well as someone else commented on the
list).

This is:
  * arr.axis
    give me an accessor the the 'Axis' objects in 'arr'
  * ['day']
    give me the 'Axis' named 'day'
  * .index
    give me the index of this 'Axis' in 'arr' (the position on the list of
    dimensions/axes)

Lluis

-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



More information about the NumPy-Discussion mailing list