[Numpy-discussion] one-offset arrays

Tim Hochberg tim.hochberg at ieee.org
Thu Aug 30 10:44:07 EDT 2001

Hi Eric,

Here are some comments on the problems you identify.

> Problem 1
> ---------
> Description
> for loops don't work with variables of type arrayone

Soon (Python 2.2?) you will be able to use the new iterator protocol to do
this correctly. So target the iterator protocol and this will begin to work
as people begin to upgrade.

> Problem 2
> ---------
> Description
> Slicing an arrayone from 0 doesn't generate an error but it should.

I was going to suggest removing __getslice__, and only using __getitem__.
However, the slices recieved by __getitem__ *sometimes* gets their first
value filled in with zero (in the same cases that __getslice__ is called)
instead of None. I regard this as a bug/misfeature and I just reported it on

> Problem 3
> ---------
> Description
> Negative subscripts return a slice offset by -1 from the expected
> result.

This one _should_ be fixable just by removing __getslice__ and working with
__getitem__ only. (getitem is called instead of getslice). However it fails
for the same reason that this fix fails for problem 2. Mumble.

Note that both fixes work fine if you always include the second colon. One
approach would be to do all [] operations in getitem and have getslice raise
an error. This would force your users to always use a[-3:-2:] instead of
a[-2:-2]. The former can be made to work since it calls getitem with the raw
values [slice(-3,-2,None)] as opposed to munging them like the latter does.


More information about the NumPy-Discussion mailing list