python | num py . ndaarray . _ _ pow ()

哎哎哎:# t0]https://www . geeksforgeeks . org/python-num py-num py-ndaarray- _ pow _/

借助**Numpy numpy.ndarray.__pow__()**方法,我们将获得所有元素供电的,其值在numpy.ndarray.__pow__()方法中作为参数提供。

语法:n 数组。pow($self,value,mod=None,/)

返回:功率(自身,数值,mod)

示例#1 : 在此示例中,我们可以看到每个元素都使用ndarray.__pow__()方法中作为参数提供的值供电。

# import the important module in python
import numpy as np

# make an array with numpy
gfg = np.array([1, 2, 3, 4, 5])

# applying ndarray.__pow__() method
print(gfg.__pow__(3))

Output:

[  1   8  27  64  125]

例 2 :

# import the important module in python
import numpy as np

# make an array with numpy
gfg = np.array([[1, 2, 3, 4, 5],
                [6, 5, 4, 3, 2]])

# applying ndarray.__pow__() method
print(gfg.__pow__(2))

Output:

[[ 1  4  9 16 25]
 [36 25 16  9  4]]