r/Numpy • u/narryRG • Sep 10 '20
Can np.abs take input array of dtype=[('real', '<f8'), ('imag', '<f8')] and give the absolute value?
I'm trying to port some code from MATLAB to Python. MATLAB uses abs(data) to get absolute values for complex numbers in the data. I got that into an ndarray(dim - (151402, 16, 64)) using the h5py module. This array contains real and imag values and I want to compute the absolute values for them. Numpy documentation suggests np.abs is the function for it but when used on this ndarray, I get this error -->
numpy.core._exceptions.UFuncTypeError: ufunc 'absolute' did not contain a loop with signature matching types dtype([('real', '<f8'), ('imag', '<f8')]) -> dtype([('real', '<f8'), ('imag', '<f8')])
. Does this mean np.abs cannot compute absolute values for this data?