[Numpy-discussion] Infinity as nan as real part

Robert Kern robert.kern@gmail....
Wed Jun 25 14:05:31 CDT 2008


On Wed, Jun 25, 2008 at 07:42, Stéfan van der Walt <stefan@sun.ac.za> wrote:
> Hi all,
>
> Why can't a person construct a complex number with an infinite complex
> part and a zero real part?
>
> 1 + 1j*np.inf == (nan + infj) # because np.inf * 1j == (nan + infj)

In [1]: from numpy import *

In [3]: 1j == (0+1j)
Out[3]: True

In [4]: 0*inf
Out[4]: nan

> There is a workaround:
>
> z = np.array([0], dtype=complex)
> z.imag = np.inf
>
> but that's not very pleasant.

In [5]: complex(0, inf)
Out[5]: infj

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