On this page
numpy.lib.scimath.sqrt
lib.scimath.sqrt(x)[source]-
Compute the square root of x.
For negative input elements, a complex value is returned (unlike
numpy.sqrtwhich returns NaN).- Parameters
-
xarray_like-
The input value(s).
- Returns
-
outndarray or scalar-
The square root of
x. Ifxwas a scalar, so isout, otherwise an array is returned.
See also
Examples
For real, non-negative inputs this works just like
numpy.sqrt:>>> np.lib.scimath.sqrt(1) 1.0 >>> np.lib.scimath.sqrt([1, 4]) array([1., 2.])But it automatically handles negative inputs:
>>> np.lib.scimath.sqrt(-1) 1j >>> np.lib.scimath.sqrt([-1,4]) array([0.+1.j, 2.+0.j])
© 2005–2021 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.20/reference/generated/numpy.lib.scimath.sqrt.html