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


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


numpy.tril(a,k = 0):返回三角形下部w.r.t k的数组的副本
参数:

a : input array
k : [int, optional, 0 by default]
          Diagonal we require; k>0 means diagonal above main diagonal or vice versa.

返回值:

Lower triangle of a, having same shape and data-type as a.
# Python Programming illustrating 
# numpy.tril method 
  
import numpy as geek 
  
# string input 
a = geek.matrix([[1, 21, 30],  
                 [63 ,434, 3],  
                 [54, 54, 56]]) 
  
print("Main Diagonal elements : \n", geek.tril(a), "\n") 
  
print("Diagonal above main Diagonal elements : \n", geek.tril(a, 1), "\n\n") 
  
print("Main Diagonal elements : \n", geek.tril(a, -1))

输出:


Main Diagonal elements : 
 [[  1   0   0]
 [ 63 434   0]
 [ 54  54  56]] 

Diagonal above main Diagonal elements : 
 [[  1  21   0]
 [ 63 434   3]
 [ 54  54  56]] 


Main Diagonal elements : 
 [[ 0  0  0]
 [63  0  0]
 [54 54  0]]


相关用法


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