Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
Both around and round supports complex input, but not trunc. This looks a bit abnormal.
around
round
trunc
In [1]: import numpy as np In [2]: a=np.array([complex(1+1j)]*3) In [3]: np.around(a) Out[3]: array([1.+1.j, 1.+1.j, 1.+1.j]) In [4]: np.round(a) Out[4]: array([1.+1.j, 1.+1.j, 1.+1.j]) In [5]: np.trunc(a) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-5-17494546b8df> in <module> ----> 1 np.trunc(a) TypeError: ufunc 'trunc' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
1.19.1 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]
The text was updated successfully, but these errors were encountered:
I think this is deliberate. math.trunc doesn't support floatscomplex in python either:
math.trunc
In [14]: import math In [15]: math.trunc(1.2+3.4j) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-15-25c8caeb25a5> in <module> ----> 1 math.trunc(1.2+3.4j) TypeError: type complex doesn't define __trunc__ method
I don't expect numpy to change here unless python changes first.
Edit (mattip): float -> complex
Sorry, something went wrong.
Ah, I'm reading this backwards - if we care about consistency with python, we should deprecate round(complex):
round(complex)
In [18]: round(1+2j) TypeError: type complex doesn't define __round__ method
So either we should add trunc, or deprecate round
Why don't we propose Python to add these support? :-)
No branches or pull requests
Both
around
andround
supports complex input, but nottrunc
. This looks a bit abnormal.Reproducing code example:
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: