tuple vs. list as index
Hi, Is this really obvious to everybody:
type(a)
a.shape (12, 13, 2, 5) a[(0,0)].shape (2, 5) a[[0,0]].shape (2, 13, 2, 5)
na.take(a,[0,0]).shape (2, 13, 2, 5)
Is there some explanation in the documentation ? (Is this the same in Numeric / Numeric3 ?) Thanks, Sebastian Haase
On Thu, 2005-05-12 at 17:04 -0700, Sebastian Haase wrote:
Hi, Is this really obvious to everybody:
type(a)
a.shape (12, 13, 2, 5) a[(0,0)].shape (2, 5) a[[0,0]].shape (2, 13, 2, 5) na.take(a,[0,0]).shape (2, 13, 2, 5)
Is there some explanation in the documentation ?
The distinction is not an accident and has been discussed. One thing to keep in mind with numarray indexing is that not all sequences used as indices are created equal. There is already a distinction for arrays used as indices, and an additional distinction for Bool arrays used as indices. Back to basics, the explanation is this:
a[(0,0)].shape (2, 5) a[0,0].shape (2, 5)
Those two have identical semantics because of the way Python works. Either way, the numarray indexing hooks see (0,0), i.e. not ((0,0),) for the first and (0,0) for the second.
a[[0,0]].shape (2, 13, 2, 5)
A list, on the other hand, *is* seen as ([ 0,0 ],). And we've chosen to exploit that as a shorthand for array-based-indexing making it equivalent to take() as you've shown.
(Is this the same in Numeric / Numeric3 ?)
Unless it was added recently, Numeric has no array-based-indexing. Maybe Travis or someone else can fill us in on how Numeric3 handles this. Regards, Todd
Todd Miller wrote:
On Thu, 2005-05-12 at 17:04 -0700, Sebastian Haase wrote:
Hi, Is this really obvious to everybody:
type(a)
a.shape
(12, 13, 2, 5)
a[(0,0)].shape
(2, 5)
a[[0,0]].shape
(2, 13, 2, 5)
na.take(a,[0,0]).shape
(2, 13, 2, 5)
Is there some explanation in the documentation ?
The distinction is not an accident and has been discussed. One thing to keep in mind with numarray indexing is that not all sequences used as indices are created equal. There is already a distinction for arrays used as indices, and an additional distinction for Bool arrays used as
indices. Back to basics, the explanation is this:
This same distinction is kept in Numeric3 and currently works the same way. Numeric3 should have the same semantics as Numarray. -Travis
participants (3)
-
Sebastian Haase
-
Todd Miller
-
Travis Oliphant