[Numpy-discussion] indexing of rank-0 structured arrays: why not?
robert.kern at gmail.com
Mon Jan 10 12:05:45 EST 2011
On Mon, Jan 10, 2011 at 10:08, Nils Becker <n.becker at amolf.nl> wrote:
> I noticed that I can index into a dtype when I take an element
> of a rank-1 array but not if I make a rank-0 array directly. This seems
> inconsistent. A bug?
Not a bug. Since there is no axis, you cannot use integers to index
into a rank-0 array. Use an empty tuple instead.
|1> dt = np.dtype([('x', '<f8'), ('y', '<f8')])
|2> a_rank_0 = np.zeros((), dtype=dt)
"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