[Numpy-discussion] indexing of rank-0 structured arrays: why not?
robert.kern at gmail.com
Mon Jan 10 14:16:02 EST 2011
On Mon, Jan 10, 2011 at 12:15, Nils Becker <n.becker at amolf.nl> wrote:
> your answer does work: after indexing with () I can then further index
> into the datatype.
> In : a_rank_0[()]
> Out: 0.0
> I guess I just found the fact confusing that a_rank_1 and a_rank_0
> compare and print equal but behave differently under indexing.
They do not print equal. Many things compare equal but do not behave the same.
> More precisely if I do
> In : b = a_rank_1
> In : b.shape
> Out: ()
> In : a_rank_0 == b
> Out: True
> In : b
> Out: 0.0
> works but a_rank_0 doesn't. I thought b is a rank-0 array which it
> apparently is not since it can be indexed. So maybe b should fail for
No, b is a record scalar. It can be indexed because it is often
convient to treat such records like tuples. This replaces the default
indexing behavior of scalars (which is to simply disallow indexing).
a_rank_0 is an array, so the array indexing semantics are the default,
and we do not change them.
"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