{ } Raw JSON

bundles / numpy 2.4.4 / numpy / lib / scimath / sqrt

_ArrayFunctionDispatcher

numpy.lib.scimath:sqrt

source: /numpy/lib/_scimath_impl.py :185

Signature

def   sqrt ( x )

Summary

Compute the square root of x.

Extended Summary

For negative input elements, a complex value is returned (unlike numpy.sqrt which returns NaN).

Parameters

x : array_like

The input value(s).

Returns

out : ndarray or scalar

The square root of x. If x was a scalar, so is out, otherwise an array is returned.

Examples

For real, non-negative inputs this works just like `numpy.sqrt`:
import numpy as np
np.emath.sqrt(1)
np.emath.sqrt([1, 4])
But it automatically handles negative inputs:
np.emath.sqrt(-1)
np.emath.sqrt([-1,4])
Different results are expected because: floating point 0.0 and -0.0 are distinct. For more control, explicitly use complex() as follows:
np.emath.sqrt(complex(-4.0, 0.0))
np.emath.sqrt(complex(-4.0, -0.0))

See also

numpy.sqrt

Aliases

  • numpy.emath.sqrt