numpy.tril () in Python

NumPy | Python Methods and Functions

numpy.tril (a, k = 0): returns a copy of the array with the bottom of the triangle relative to k
Parameters:

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

Returns :

 Lower triangle of a, having same shape and data-type as a. 

# Python Programming Illustrative
# numpy.tril method

 

import numpy as geek

 
# input line

a = geek.matrix ([[ 1 , 21 , 30 ], 

[ 63 , 434 , 3 ], 

[ 54 , 54 , 56 ]])

 

print ( "Main Diagonal elements:" , geek.tril (a), "" )

 

print ( "Diagonal above main Diagonal elements:" , geek.tril (a, 1 ), "" )

  

print ( " Main Diagonal elements: " , geek.tril (a, - 1 ))

Output:

 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]] 

Links:
https://docs.scipy.org/doc/numpy/reference /generated/numpy.tril.html#numpy.tril
Notes:
These NumPy-Python programs will not run by onlineID, so run them on your systems to study them

This article is provided by Mohit Gupta_OMG



Get Solution for free from DataCamp guru