[Numpy-discussion] method to calculate the magnitude squared

R Schumacher rays at blue-cove.com
Sun Sep 20 15:39:44 EDT 2015


At 10:01 AM 9/20/2015, you wrote:
>Is that not the same as
>Â  Â  np.abs(z)**2 ?
>
>It is, but since that involves taking sqrt, it is *much* slower. Even now,
>```
>In [32]: r = np.arange(10000)*(1+1j)
>
>In [33]: %timeit np.abs(r)**2
>1000 loops, best of 3: 213 µs per loop
>
>In [34]: %timeit r.real**2 + r.imag**2
>10000 loops, best of 3: 47.5 µs per loop
>
>-- Marten

Ahh yes, a full extra step, "back"
Assuming these are spectra, how does timeit do 
with scipy.signal.periodogram (using appropriate n and scaling)?

- Ray



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150920/c11e96b9/attachment.html>


More information about the NumPy-Discussion mailing list