[Numpy-discussion] strange sin/cos performance

Robert Kern robert.kern@gmail....
Tue Aug 4 12:24:15 CDT 2009

On Tue, Aug 4, 2009 at 12:19, Andrew Friedley<afriedle@indiana.edu> wrote:
> OK, have some interesting results.  First is my array creation was not
> doing what I thought it was.  This (what I've been doing) creates an
> array of 159161 elements:
> numpy.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=numpy.float32)
> Which isn't what I was after (1000 elements ranging from 0 to 2PI).  So
> the values in that array climb up to 999.999.

One uses arange() like so: numpy.arange(start, stop, step), just like
the builtin range().

You want numpy.linspace(0.0, 2*numpy.pi, 1000).

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 NumPy-Discussion mailing list