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.real(A)".
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, -- O.C.
participants (5)
-
Benjamin Root
-
Chris Barker
-
Nathaniel Smith
-
OC
-
Pauli Virtanen