numpy.triu () in Python

numpy.triu (a, k = 0): returns a copy of the array with the top 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 :

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

# Python Programming Illustrative
# NumPy. trio method

 

import numpy as geek

 
# input line

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

[ 63 , 434 , 3 ], 

[ 54 , 54 , 56 ]])

 

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

 

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

 

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

Exit :

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

Link:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.triu.html#numpy.triu
Notes:
These programs NumPy-Python will not work by network id, so run them on your systems to examine them
,
This article is provided by Mohit Gupta_OMG