numpy.tri() in Python

The tri() function of Python numpy class returns an array with ones at and below the given diagonal(k value) and zeros elsewhere.

Syntax

Parameter

R : It represents the number of rows

C : This parameter represents the number of columns. It is an optional parameter and, by default R = C

k: This parameter represents the Diagonal we require. It is an optional integer parameter, and its default value is 0. If k>0, it means the diagonal is above the main diagonal or vice versa.

dtype : It represents the data type of returned array. 

Return

This function returns an array with its lower triangle filled with ones and zero elsewhere(T[i,j] == 1 for i <= j + k, 0 otherwise).

Example 1

Output

Pin It on Pinterest

Share This