Open
Description
This is a tracker for a number of requests for making working with complex numbers a bit easier/faster
- Get just the normalized number
z/|z|
(the sgn function) (see API,ENH: Change definition of complex sign #25441, which changes the behaviour ofnp.sign
to match the Array API and extends it tocopysign
) - Get the squared modulus of a complex number
z * z.conj()
(instead of the slownp.abs(z)**2
).square
might be logical but is already defined to just doz*z
... (see abs() is slow for complex, add abs2() #3994) - A fast way to get the inverse of
angle
, i.e.,exp(1j * a) = cos(a) + 1j * sin(a)
. Note that for large angle arrays,exp(1j*a)
needlessly triples memory use for the input (see Have anexp
for pure imaginary numbers #5625; somewhat related:sincos
function, see Implement sincos() (Trac #2034) #2626; discussion moved to ENH: Create a place for "optimization" ufuncs #18483) - Possibly, combined
abs
andangle
and their inverse, perhaps most logical as part of providing polar to cartesian transformations (see ENH: Add to numpy simple functions for transform coordinate systems #5228)
EDIT (2021-Jun-25): if there is worry about making the numpy API too big, one option might be to make this part of numpy.lib.scimath
(which I must admit I didn't know about until today; I see now that it should be np.emath
- https://numpy.org/devdocs/reference/routines.emath.html). Though perhaps that should stay reserved for complex continuations real->complex
like for sqrt
.