[Numpy-discussion] numpy.complex

OC oc-spam66@laposte....
Fri Jul 20 15:17:27 CDT 2012

The syntax "numpy.complex(A)" seems to be the most natural and obvious 
thing a user would want for casting an array A to complex values.

Expressions like "A.astype(complex)", "array(A, dtype=complex)", 
"numpy.complex128(A)" are less obvious, especially the last two ones, 
which look a bit far-fetched.

Of course, these tricks can be learned. But Python is a language where 
natural and obvious things most often work as expected. Here, it is not 
the case.

It also breaks the Principle of Least Astonishment, by comparison with 

> numpy.complex is just a reference to the built in complex, so only works
> on scalars:
> In [5]: numpy.complex is complex
> Out[5]: True

Thank you for pointing this out.

What is the use of storing the "complex()" built-in function in the 
numpy namespace, when it is already accessible from everywhere?

Best regards,


More information about the NumPy-Discussion mailing list