当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.tril_indices()用法及代码示例


numpy.tril_indices()函数返回(n,m)数组的lower-triangle的索引。

用法: numpy.tril_indices(n, k = 0, m = None)
参数:
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.

代码1:

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

输出:

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


代码2:

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

输出:

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

相关用法


注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 numpy.tril_indices() function | Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。