numpy.tri () in Python

NumPy | Python Methods and Functions

numpy.tri (R, C = No, k = 0, dtype = & # 39; float & # 39;): Creates an array with 1 at and below the given diagonal (about k) and 0 elsewhere. 
Parameters :

  R:  Number of rows  C:  [optional] Number of columns; By default R = C  k:  [int, optional, 0 by default] Diagonal we require; k & gt; 0 means diagonal above main diagonal or vice versa.  dtype:  [optional, float (byDefault)] Data type of returned array. 

# Python program illustrating
# numpy.tri method

 

import numpy as geek

 

print ( "tri with k = 1:" , geek.tri ( 2 , 3 , 1 , dtype = float ), "" )

 

print ( " tri with main diagonal: " , geek.tri ( 3 , 5 , 0 ), "" )

 

print ( "tri with k = -1:" , geek.tri ( 3 , 5 , - 1 ), "" )

Exit:

 tri with k = 1: [[1. 1. 0.] [1. 1. 1.]] tri with main diagonal: [[1. 0. 0. 0. 0 .] [1. 1. 0. 0. 0.] [1. 1. 1. 0. 0.]] tri with k = -1: [[0. 0. 0. 0. 0.] [1. 0. 0. 0. 0.] [1. 1. 0. 0. 0.]]  

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



Get Solution for free from DataCamp guru