numpy.lib.scimath.sqrt

lib.scimath.sqrt(x)[源代码]

计算x的平方根。

对于负输入元素,将返回一个复杂值(与 numpy.sqrt 返回NaN)。

参数
xarray_like

输入值。

返回
outndarray或scalar

平方根 x .如果 x 是标量,也是标量 out ,否则返回数组。

参见

numpy.sqrt

实例

对于真正的非负输入,这就像 numpy.sqrt

>>> np.lib.scimath.sqrt(1)
1.0
>>> np.lib.scimath.sqrt([1, 4])
array([1.,  2.])

它自动处理负输入:

>>> np.lib.scimath.sqrt(-1)
1j
>>> np.lib.scimath.sqrt([-1,4])
array([0.+1.j, 2.+0.j])