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

Robert Kern robert.kern@gmail....
Mon Jul 12 20:18:00 CDT 2010

```On Mon, Jul 12, 2010 at 17:30, Rob Speer <rspeer@mit.edu> wrote:
> rec['305'] extracts a single value from a single record.

No, in Neil's example `rec` was a structured array. You can index
structured arrays using the names of the record members, not just
scalars.

> arr.named[:,305] extracts an *entire column* from a 2-D datarray,
> returning you a 1-D datarray.

And this is exactly what rec['305'] would get you.

In [1]: dt = np.dtype([('201', float), ('305', float), ('410', float)])

In [2]: rec = np.arange(12).astype(float).view(dt)

In [3]: rec
Out[3]:
array([(0.0, 1.0, 2.0), (3.0, 4.0, 5.0), (6.0, 7.0, 8.0), (9.0, 10.0, 11.0)],
dtype=[('201', '<f8'), ('305', '<f8'), ('410', '<f8')])

In [4]: rec['305']
Out[4]: array([  1.,   4.,   7.,  10.])

> Once again, 1-D record arrays and 2-D labeled arrays look similar when
> you print them, but the data structures are so unrelated that there is
> really not much point in comparing them any further.

Not really. 1-D structured arrays can and do work well for the very
common case where one has unlabeled rows and labeled columns. They are
also a little bit more flexible in that the columns can be
heterogeneous in dtype, as columns are wont to do.

May I politely suggest that, just as some people did not do a
sufficient job of reading the datarray proposal to understand how they
differ from structured arrays, you do not know as much about
structured arrays to understand the ways in which they are similar to
labeled arrays? Understanding both the similarities and differences is
important because both are going to be living in the same ecosystem
with overlapping niches.

--
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
```