Saturday, December 13, 2025
HomeLanguagesnumpy.tril_indices() function | Python

numpy.tril_indices() function | Python

numpy.tril_indices() function return the indices for the lower-triangle of an (n, m) array.

Syntax : numpy.tril_indices(n, k = 0, m = None)
Parameters :
n : [int] The row dimension of the arrays for which the returned indices will be valid.
k : [int, optional] Diagonal offset.
m : [int, optional] The column dimension of the arrays for which the returned arrays will be valid. By default m is taken equal to n.
Return : [tuple of arrays] The indices for the triangle. The returned tuple contains two arrays, each with the indices along one dimension of the array.

Code #1 :




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


Output :

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

 
Code #2 :




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


Output :

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

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS