Tuesday, October 7, 2025
HomeLanguagesPython | Numpy np.triu_indices

Python | Numpy np.triu_indices

With the help of np.triu_indices() method, we can get the indices for the upper triangle of an [n, m] array by using np.triu_indices() method.

Syntax : np.triu_indices(n, m)

Return : Return the indices for the upper triangle.

Example #1 :
In this example we can see that by using np.triu_indices() method, we are able to get the indices for the upper triangle of an [n, m] array by using this method.




# import numpy and triu_indices
import numpy as np
  
# using np.triu_indices() method
gfg = np.triu_indices(2, 3)
  
print(gfg)


Output :

(array([], dtype = int64), array([], dtype = int64))

Example #2 :




# import numpy and triu_indices
import numpy as np
  
# using np.triu_indices() method
gfg = np.triu_indices(4)
  
print(gfg)


Output :

array([], dtype = int64)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32339 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6827 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS