[Numpy-discussion] range/arange

Arnd Baecker arnd.baecker at web.de
Thu Apr 13 10:07:14 CDT 2006


On Thu, 13 Apr 2006, Lars Bittrich wrote:

> Hi,
>
> On Thursday 13 April 2006 11:07, Pierre GM wrote:
> > Could any of you explain me why the two following commands give different
> > results ? It's mere curiosity, for my personal edification.
> >
> > [(m-5)/10 for m in arange(1,10)]
> > [0, 0, 0, 0, 0, 0, 0, 0, 0]
> >
> > [(m-5)/10 for m in range(1,10)]
> > [-1, -1, -1, -1, 0, 0, 0, 0, 0]
>
> I have no idea where the reason is located exactly, but it seems to be caused
> by different types of range and arange.


Interestingly with Numeric you get the following:

In [1]: from Numeric import *
In [2]: [(m-5)/10 for m in arange(1,10)]
Out[2]: [-1, -1, -1, -1, 0, 0, 0, 0, 0]
In [3]: type(arange(1,10)[0])
Out[3]: <type 'int'>

Will this cause any trouble for projects
transitioning from Numeric to numpy?
Presumably a proper explanation (which?)
should go into the scipy wiki ("Converting from Numeric").


> In [15]:type(arange(1,10)[0])
> Out[15]:<type 'int32scalar'>
>
> In [14]:type(range(1,10)[0])
> Out[14]:<type 'int'>
>
> If you use for example:
>
> In [16]:-1/10
> Out[16]:-1
>
> you get the normal behavior of the "floor" function.
>
> In [17]:floor(-.1)
> Out[17]:-1.0
>
> The behavior of int32scalar seems more intuitive to me.

Me too.

Best, Arnd




More information about the Numpy-discussion mailing list