【NumPy】 之常见运算2(np.power 幂运算)
____tz_zsnp.powerpower(x1, x2, /, out=None, *, where=True, casting=‘same_kind’, order=‘K’, dtype=None, subok=True[, signature, extobj])幂运算(指数运算),对x1中的元素进行x2中元素次幂的计算。x1 : array_like,底数x2 : array_l...
·
____tz_zs
np.power
power(x1, x2, /, out=None, *, where=True, casting=‘same_kind’, order=‘K’, dtype=None, subok=True[, signature, extobj])
幂运算(指数运算),对x1中的元素进行x2中元素次幂的计算。
x1 : array_like,底数
x2 : array_like,指数
https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.power.html
import numpy as np
result = np.power([-2, -1, 0, 1, 2], 3)
print(result) # [-8 -1 0 1 8]
result = np.power([-2, -1, 0, 1, 2], [3, 3, 3, 3, 3])
print(result) # [-8 -1 0 1 8]
result = np.power([-2, -1, 0, 1, 2], [0, 1, 2, 3, 4])
print(result) # [ 1 -1 0 1 16]
result = np.power([-2, -1, 0, 1, 2], np.array([[0, 1, 2, 3, 4], [0, 0, 0, 0, 0]]))
print(result)
"""
[[ 1 -1 0 1 16]
[ 1 1 1 1 1]]
"""
更多推荐



所有评论(0)