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


Python numpy.mask_indices()用法及代码示例


numpy.mask_indices()函数在给定屏蔽函数的情况下返回索引以访问(n,n)数组。

用法: numpy.mask_indices(n, mask_func, k = 0)
参数:
n :[int] The returned indices will be valid to access arrays of shape (n, n).
mask_func :[callable] A function whose call signature is similar to that of triu, tril.
k :[scalar] An optional argument which is passed through to mask_func.
Return :[tuple of arrays] The n arrays of indices corresponding to the locations where mask_func(np.ones((n, n)), k) is True.

代码1:

# Python program explaining 
# numpy.mask_indices() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.mask_indices(3, geek.triu) 
  
print (gfg)

输出:

(array([0, 0, 0, 1, 1, 2]), array([0, 1, 2, 1, 2, 2]))


代码2:

# Python program explaining 
# numpy.mask_indices() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.mask_indices(3, geek.triu, 1) 
  
print (gfg)

输出:

(array([0, 0, 1]), array([1, 2, 2]))

相关用法


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