[Numpy-discussion] rank-0 arrays

Perry Greenfield perry at stsci.edu
Mon Sep 16 14:48:06 CDT 2002

Konrad Hinsen writes:
> "Chris Barker" <Chris.Barker at noaa.gov> writes:
> > use one as an index? Personally, this is what has bit me in the past: I
> At least up to Python 1.5, no, indices have to be of integer type. I
> don't know if that condition was extended in later versions.
> > could use A[3,2] as an index if A was type "Int" but not if it was
> > "Int16" for example.
> Ehmmm... Are you sure that is the right example? The restriction is on
> the type of the index, not on the type of the array.
I think Chris is referring to the fact that Numeric returns a rank-0
array for A[3,2] if A is of type Int16, and that value cannot be used
as in index in Python sequences (at least for now; nothing technical
prevents it from being implemented to accept object that have an
__int__ method). This is the odd inconsistency Numeric has now. If
A were a 1-d Int16 array then A[2] would not be a rank-0 array,
nor is A[3,2] a rank-0 array if A is of type Int32 (apparently because
a Python scalar type suffices). Why it gives rank-0 for 2-d and not
1-d I have no idea.

More information about the Numpy-discussion mailing list