[Numpy-discussion] More PEP comments
tim.hochberg at cox.net
Sun Feb 20 15:25:23 CST 2005
From the PEP:
> integers in index arrays can be negative to mean selection from the end
> of the array. Indices that are too large will be taken to mean the
> last element. Indicies that are too negative will mean
> the first element.
Here's another little piece of the PEP that I feel should be
reconsidered. In the absence of a compelling reason to do otherwise, the
indices in index arrays should behave just as if one were using that
index directly as in index tuple. And, index tuples should match the
behaviour Python lists. In other words:
alist[i] == anarray[i] == anarray(array([i]))
In order to make this equivalence work, both anarray[i] and
anarray(array([i])) need to raise index errors when i is too large or
too negative. And for consistency this rule should continue to apply
when the index is a tuple rather than a simple integer index.
This is more or less how numarray works and I think that's the right
choice. [However, I did notice that numarray 1.1 produced nonsensical
answers when index arrays with values that were too negative, when they
were too positive they worked as I would expect and produced an error].
More information about the Numpy-discussion