[NumPy-Tickets] [NumPy] #1564: numpy.arange returns array with wrong length
NumPy Trac
numpy-tickets@scipy....
Wed Jul 28 15:01:33 CDT 2010
#1564: numpy.arange returns array with wrong length
-------------------------+--------------------------------------------------
Reporter: crassus | Owner: somebody
Type: defect | Status: closed
Priority: high | Milestone: 1.5.0
Component: numpy.core | Version: 1.3.0
Resolution: invalid | Keywords: arange length
-------------------------+--------------------------------------------------
Changes (by pv):
* status: new => closed
* resolution: => invalid
Comment:
The result from `arange` is defined as: numbers between [start, stop),
spaced by step.
What you are seeing is a consequence of inexact floating point arithmetic.
{{{
>>> from math import ceil
>>> step = 1.0/400000
>>> stop = 971 * step
>>> stop/step
971.00000000000011
}}}
There are 972 numbers fitting in the interval.
You should use `numpy.linspace`, if you want a given number of equally
spaced items.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1564#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list