Thursday, December 11, 2025
HomeLanguagesnumpy.mask_indices() function | Python

numpy.mask_indices() function | Python

numpy.mask_indices() function return the indices to access (n, n) arrays, given a masking function.

Syntax : numpy.mask_indices(n, mask_func, k = 0)
Parameters :
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.

Code #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)


Output :

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

 
Code #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)


Output :

(array([0, 0, 1]), array([1, 2, 2]))
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7195 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS