[Numpy-discussion] range/arange

Lars Bittrich lars.bittrich at googlemail.com
Thu Apr 13 02:30:01 EDT 2006


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.

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.

Best regards,
Lars




More information about the NumPy-Discussion mailing list