[Numpy-discussion] arange(-10)

Pearu Peterson peterson at math.utwente.nl
Tue Oct 8 03:40:02 CDT 2002


On Mon, 7 Oct 2002, Todd Miller wrote:

> Pearu Peterson wrote:
>
> >On Mon, 7 Oct 2002, Todd Miller wrote:
> >
> >>The subject line contains what I consider to be an invalid range
> >>expression.   Numarray, now and always, reacts badly to it.  Currently,
> >>numarray tries to allocate a multi-gigabyte array.   In the past, it has
> >>dumped core.
> >>
> >>The question is, what should it do?
> >>
> >>1. raise ValueError, "Invalid negative range expression"     (my +1)
> >>2. zeros((0,), 'l')
> >>                  (Numeric does this)
> >>
> >>Is there a good justification to keep the existing Numeric behavior?
> >> Any other suggestions?
> >>
> >
> >Does Numarray support empty arrays? If yes, I'd vote for Python behavior:
> >
> Numarray has no problem with empty arrays so both choices are easy to
> implement.  It apparently has a different repr (than Numeric) for
> "nothing" which is:
>
> array([])

Hmm, so it means that Numeric.arange is consistent with Python range after
all.  Then I'd like to change my vote from exception to array([]) (if it
is not too late).

Rationale: sometimes using

  range(i1) + range(i2) + range(i3)

can save lots of code if the indices i1,i2,i3 can also be negative with
the meaning that the resulting lists are then empty. If using arange, then
the above would be equivalent to

  concatenate((arange(i1),arange(i2),arange(i3)))

or

  concatenate(map(arange,[i1,i2,i3]))

for short. Now, if arange would raise an exception if one of i1,i2,i3 is
negative, then the above would not work without checking i1,i2,i3 first.
And I find that bad because additional (read: meaningless) code is
needed.

Pearu






More information about the Numpy-discussion mailing list