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 :
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 :
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]))
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.Dive into the future of technology - explore the
Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
22 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...