-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
np.median on a complex array return incorrect value for the imaginary part #12943
Comments
The result for complex types depends on the sort order of complex, which will not give you what you want. I am not convinced that returning the medians of the real and imaginary parts as you desire makes much more sense as a default. For multidimensional points, the geometric median might be a better choice. |
Hmm, frankly, it seems to me that median on complex is probably just broken (at least unless the complex numbers have some additional properties)? Should we deprecate it, or put a user warning? |
@seberg Deprecation seems reasonable. Should probably raise the issue on the list first. |
I agree that, outside the context of NumPy, taking the median of a set of complex numbers is not well-defined. However, my understanding is that NumPy has imposed an ordering on the complex numbers by using lexicographic ordering of the real and imaginary parts. This affects all functions that are based on the ordering of the inputs, including the functions and methods
are correct. |
There is some interest in deprecating this: #15981 |
Calling np.median on a complex array return a complex number with correct real part, but incorrect imaginary part. Calling np.median on the real and imaginary part of the complex array separately return the correct values.
Reproducing code example:
d = (1 + 1j) + np.random.randn(10000) + 1j * np.random.randn(10000)
print 'median(d) : %.3f + %.3f i' % (np.median(d).real, np.median(d).imag)
print 'median(d.real): %.3f' % np.median(d.real)
print 'median(d.imag): %.3f' % np.median(d.imag)
median(d) : 1.002 + 0.124 i
median(d.real): 1.002
median(d.imag): 0.998
Numpy version: 1.15.4
The text was updated successfully, but these errors were encountered: