[Numpy-discussion] method to calculate the magnitude squared
Marten van Kerkwijk
m.h.vankerkwijk at gmail.com
Sat Oct 10 13:14:28 EDT 2015
> We tend to avoid adding methods. 2) would be a very easy enhancement,
just a slight modification of sqr.
Did you mean `np.square`? Sadly, that doesn't do the right thing:
`np.square(1+1j)` yields `2j`, while one wants `c*c.conj()` and thus `2`.
Or, for fastest speed, really just `c.real**2 + c.imag**2`.
My guess would be that a new ufunc, say `np.abs2` or `np.modulus2` or so,
would be more appropriate than defining a new method. I'd also be hesitant
to define a new private method -- I like how those usually are just used to
override python basics.
-- Marten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151010/b3c9ba71/attachment.html>
More information about the NumPy-Discussion
mailing list