当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Numpy MaskedArray.__pow__用法及代码示例


numpy.ma.MaskedArray class是ndarray的子​​类,旨在处理缺少数据的数字数组。借助Numpy MaskedArray .__ pow__方法,我们可以使用作为参数提供的值来增强元素。

用法: numpy.MaskedArray.__pow__

返回:计算自身的幂,掩盖潜在的NaN。


范例1:
在此示例中,我们可以看到,在应用MaskedArray.__pow__()之后,我们可以看到每个元素都使用作为参数提供的值获得能量。

   
# import the important module in python  
import numpy as np  
      
# make an array with numpy  
gfg = np.ma.array([1, 2, 3, 4, 5])  
      
# applying MaskedArray.__pow__() method  
print(gfg.__pow__(3)) 
输出:
[  1   8  27  64 125]


范例2:

# import the important module in python  
import numpy as np  
      
# make an array with numpy  
gfg = np.ma.array([[1, 2, 3, 4, 5],  
                [6, 5, 4, 3, 2]])  
      
# applying MaskedArray.__pow__() method  
print(gfg.__pow__(2)) 
输出:
[[ 1  4  9 16 25]
 [36 25 16  9  4]]


相关用法


注:本文由纯净天空筛选整理自Shivam_k大神的英文原创作品 Python | Numpy MaskedArray.__pow__。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。