numpy.lib.scimath.power#
- lib.scimath.power(x, p)[source]#
傳回 x 的 p 次方,(x**p)。
如果 x 包含負值,則輸出會轉換為複數域。
- 參數:
- x類陣列
輸入值(們)。
- p整數的類陣列
x 的次方(們)。如果 x 包含多個值,則 p 必須是純量,或包含與 x 相同數量的數值。在後者的情況下,結果為
x[0]**p[0], x[1]**p[1], ...
。
- 回傳值:
- outndarray 或純量
x**p
的結果。如果 x 和 p 是純量,則 out 也是,否則會回傳一個陣列。
另請參閱
範例
>>> import numpy as np >>> np.set_printoptions(precision=4)
>>> np.emath.power(2, 2) 4
>>> np.emath.power([2, 4], 2) array([ 4, 16])
>>> np.emath.power([2, 4], -2) array([0.25 , 0.0625])
>>> np.emath.power([-2, 4], 2) array([ 4.-0.j, 16.+0.j])
>>> np.emath.power([2, 4], [2, 4]) array([ 4, 256])