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

Rob Speer rspeer at MIT.EDU
Thu Jul 8 12:02:52 EDT 2010


> While I haven't had a chance to really look in-depth at the changes
> myself (I'm a busy man! So many mailing lists!), I so far like the
> look and sound of them. That's just my opinion, though.

If people are okay with the attribute magic, I have a proposal for more of it.

In my own project where I use labeled arrays
(http://github.com/commonsense/divisi2), I don't have labeled axes.
But I assumed everything was 1 or 2-D, and gave the 2-D matrices
methods like "row_named", "col_named", etc., to encourage readable
code.

With the current implementation of datarray, I could get that by
labeling the axes "row" and "col", except the moment you transpose a
matrix like that you get rows named "col" and columns named "row", so
that's not the right answer.

My proposal is that datarray.row should be equivalent to
datarray.axes[0], and datarray.column should be equivalent to
datarray.axes[1], so that you can always ask for something like
"arr.column.named(2010)" (replace those with square brackets if you
like).

Not sure yet what the right way is to generalize this to 1-D and n-D.
-- Rob



More information about the NumPy-Discussion mailing list