當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy scimath.sqrt用法及代碼示例

本文簡要介紹 python 語言中 numpy.lib.scimath.sqrt 的用法。

用法:

lib.scimath.sqrt(x)

計算 x 的平方根。

對於負輸入元素,返回一個複數值(與返回 NaN 的 numpy.sqrt 不同)。

參數

x array_like

輸入值。

返回

out ndarray 或標量

x 的平方根。如果 x 是標量,則輸出,否則返回數組。

例子

對於真實的非負輸入,這就像 numpy.sqrt 一樣工作:

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

但它會自動處理負輸入:

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

相關用法


注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.lib.scimath.sqrt。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。