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]))
相關用法
- Python Wand function()用法及代碼示例
- Python sum()用法及代碼示例
- Python map()用法及代碼示例
- Python str()用法及代碼示例
- Python int()用法及代碼示例
- Python cmp()用法及代碼示例
- Python ord()用法及代碼示例
- Python dir()用法及代碼示例
- Python tell()用法及代碼示例
- Python oct()用法及代碼示例
- Python hex()用法及代碼示例
- Python id()用法及代碼示例
- Python now()用法及代碼示例
- Python strftime()用法及代碼示例
- Python numpy.ma.where()用法及代碼示例
- Python turtle.pen()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.mask_indices() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。