-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
operation on complex number data #553
Comments
A short example for convenience: import xray
import numpy as np
arr = xray.DataArray(np.random.randn(2, 3) + 1j*np.random.randn(2, 3))
np.abs(arr) # returns a xray DataArray
np.angle(arr) # returns a numpy ndarray |
I realized this is also an issue in Pandas. So I also reported here: |
There's nothing we can do about However, we could certainly add |
That would be great to add |
There is an open issue at numpy about this in numpy/numpy#6266 Also, for future reference, locally re-defining import numpy.core.numeric as _nx
def angle(z, deg=0):
"""Compute the angle of an xarray
Parameters
----------
z : array_like
A complex number or sequence of complex numbers.
deg : bool, optional
Return angle in degrees if True, radians if False (default).
Returns
-------
angle : ndarray or scalar
The counterclockwise angle from the positive real axis on
the complex plane, with dtype as numpy.float64.
See: https://github.com/pydata/xarray/issues/553
https://github.com/numpy/numpy/blob/v1.13.0/numpy/lib/function_base.py#L2072-L2115
"""
if deg:
fact = 180/pi
else:
fact = 1.0
if (issubclass(z.dtype.type, _nx.complexfloating)):
zimag = z.imag
zreal = z.real
else:
zimag = 0
zreal = z
return np.arctan2(zimag, zreal) |
You can also use |
@shoyer Aww, great. Thanks for pointing this out. |
@shoyer What is the recommended way to keep an DataArray when computing angles ? Thanks ! |
The short answer is that we shouldn't remove
|
Thanks ! |
Hello,
Would it be possible to add complex function operation on xray.DataArray ?
Function like np.sin, np.abs works properly on xray.DataArray containing complex numbers and
returns a DataArray (as expected).
However, np.real, np.imag, np.angle operation return an numpy.ndarray array instead of DataArray...
The text was updated successfully, but these errors were encountered: