I just realized that doing
x.real*x.real+x.imag*x.imag
is three times faster than doing
abs(x)**2
where x
You can try to use lambda:
lambda
abs2 = lambda x : x.real*x.real+x.imag*x.imag
then call it by:
y = abs2(x)