librosa.util.abs2
- librosa.util.abs2(x, dtype=None)[source]
Compute the squared magnitude of a real or complex array.
This function is equivalent to calling np.abs(x)**2 but it is slightly more efficient.
- Parameters:
- xnp.ndarray or scalar, real or complex typed
The input data, either real (float32, float64) or complex (complex64, complex128) typed
- dtypenp.dtype, optional
The data type of the output array. If not provided, it will be inferred from x
- Returns:
- pnp.ndarray or scale, real
squared magnitude of x
Examples
>>> librosa.util.abs2(3 + 4j) 25.0
>>> librosa.util.abs2((0.5j)**np.arange(8)) array([1.000e+00, 2.500e-01, 6.250e-02, 1.562e-02, 3.906e-03, 9.766e-04, 2.441e-04, 6.104e-05])