On Mon, Jan 10, 2011 at 12:15, Nils Becker <n.bec...@amolf.nl> wrote:
> Robert,
>
> your answer does work: after indexing with () I can then further index
> into the datatype.
>
> In [115]: a_rank_0[()][0]
> Out[115]: 0.0
>
> I guess I just found the fact confusing that a_rank_1[0] 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 [117]: b = a_rank_1[0]
>
> then
>
> In [118]: b.shape
> Out[118]: ()
>
> and
>
> In [120]: a_rank_0 == b
> Out[120]: True
>
> but
>
> In [119]: b[0]
> Out[119]: 0.0
>
> works but a_rank_0[0] doesn't. I thought b is a rank-0 array which it
> apparently is not since it can be indexed. So maybe b[0] should fail for
> consistency?

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.

-- 
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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to