[Numpy-discussion] BOF notes: Fernando's proposal: NumPy ndarray with named axes
Joshua Holbrook
josh.holbrook@gmail....
Fri Jul 9 20:44:08 CDT 2010
On Fri, Jul 9, 2010 at 5:26 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Fri, Jul 9, 2010 at 6:11 PM, Joshua Holbrook <josh.holbrook@gmail.com> wrote:
>
>> I think I like being able to group ticks with their axis, so I know
>> which ticks belong to which axis without having to scan back-and-forth
>> between them to match them up. Do you think you can explain why you
>> would prefer to separate labels and ticks?
>
> You wouldn't have to know that (labels, ticks) has to be a tuple. If
> you write it is a list [label, tick] it doesn't work. As is, you don't
> have the option to let labels be any hashable object, like tuples
> since tuples have a special meaning.
>
> It would treat labels and ticks on an equal footing. And it would be
> the same signature as Axis which has separate label and ticks
> parameters. And you could make a tick only DataArray (i.e., no axis
> labels) without writing None for each axis label. That's was my main
> concern since that it what I plan to do at first.
>
> So I could write:
>
>>>> DataArray([[1, 2], [3, 4]], ticks=[['A', 'B'], ['C', 'D']])
>
> instead of
>
>>>> DataArray([[1, 2], [3, 4]], ((None, ['A','B']), (None, ['C', 'D'])))
>
> Less likely to have problems with matching parentheses.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
It's definitely true that making ticks sans-axes is made much easier this way.
Maybe we can take advantage of zip somehow? Here's what I mean:
In [25]: axes=['row','col']
In [26]: labels=[['a','A'],['b','B']]
In [27]: zip(axes,labels)
Out[27]: [('row', ['a', 'A']), ('col', ['b', 'B'])]
Or, in reverse:
In [32]: zip(*(('row', ['a', 'A']), ('col', ['b', 'B'])))
Out[32]: [('row', 'col'), (['a', 'A'], ['b', 'B'])]
In other words, each method is pretty much a zipped version of the
other, minus some wrapping lists and list<-->tuple things going on.
As an aside, I don't think we'd want to keep the current string
representation of the datarray as-is. I know I don't like it!
--Josh
More information about the NumPy-Discussion
mailing list