[Numpy-discussion] Complex arange

Robert Kern robert.kern@gmail....
Thu Feb 1 19:01:19 CST 2007

```Russel Howe wrote:

(It's good to see so many Rudds seeing sense and using Python and numpy.  ;-))

> Should this work?
>
> Python 2.4.3 (#1, Dec 27 2006, 21:18:13)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
>  >>> import numpy as N
>  >>> N.__version__
> '1.0.2.dev3531'
>  >>> N.arange(1j, 5j)
> array([], dtype=complex128)
>  >>> N.arange(1j, 5j, 1j)
> array([], dtype=complex128)
>
> Currently, the real direction is determined to be of zero length
> (multiarraymodule.c _calc_length), and the length of the array is the
> minimal length.  I can understand the first one not working (default
> step is 1, it takes 0 of those to cover this range), but the second
> seems like a bug.

arange() is pretty much only defined for real numbers. For general z0, z1, and
dz, there is no guarantee that (z1 - z0)/dz is a real number as it needs to be.
dz may point in a different direction than (z1-z0). For example, what should
arange(1j, 5j, 1) do? Numeric raises an exception here, and I thing numpy
should, too.

Of course, linspace() is generally preferred for floating point types regardless
of whether complex or real. It's difficult to predetermine whether the stop
value will be included or not. And since you give it a count instead of a step
size, we can guarantee that the step does lie along the vector (z1-z0).

In [8]: linspace(1j, 5j, 5)
Out[8]: array([ 0.+1.j,  0.+2.j,  0.+3.j,  0.+4.j,  0.+5.j])

--
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
```