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


Python Numpy ndarray.__ipow__()用法及代碼示例

借助Numpy ndarray.__ipow__()方法,我們將使用由參數中提供的值提供動力的所有元素numpy.ndarray.__ipow__()方法。

用法: ndarray.__ipow__($self, value, /)

返回:self**=value


範例1:
在此示例中,我們可以看到,每個元素都使用作為參數提供的值進行賦能ndarray.__ipow__()方法。

# 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.__ipow__() method 
print(gfg.__ipow__(3))
輸出:
[  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.__ipow__() method 
print(gfg.__ipow__(2))
輸出:
[[ 1  4  9 16 25]
 [36 25 16  9  4]]


相關用法


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