Creating arithmetic sequences

Robert Kern robert.kern at gmail.com
Wed Apr 16 19:18:55 EDT 2008


mmm wrote:
> I wrote the code below to create simple arithmetic sequences that are
> iter-able
> I.e.,  this would basically combine the NUMPY arange(start,end,step)
> to range(start,end),  with step not necessarily an integer.
> 
> The code below is in its simplest form and I want to generalize the
> sequence types (multiplicative, cumulative, gauss ...), but first I
> need the simple SEQA( ) function to be more robust.   The problem is
> the three test code functions produces different results based on
> step. I understand why steps such as 0.1 have rounding and  machine
> math issues, and before I try to solve this I thought it was worth
> asking if this problem has been solved (so I do not re-invent the
> wheel).

Using numpy.arange() with floats is known to be problematic, and it is 
discouraged. Almost all of the use cases are better served with numpy.linspace() 
which accepts a start, end, and the number of points rather than a step.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list