VOOZH about

URL: https://www.geeksforgeeks.org/python/numpy-tri-python/

⇱ numpy.tri() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

numpy.tri() in Python

Last Updated : 9 Mar, 2022
numpy.tri(R, C = None, k = 0, dtype = 'float') : Creates an array with 1's at and below the given diagonal(about k) and 0's 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>0 means diagonal above main diagonal or vice versa.
dtype : [optional, float(byDefault)] Data type of returned array. 
Output :
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.]] 
References : https://numpy.org/doc/stable/reference/generated/numpy.tri.html Note : These NumPy-Python programs won't run on online IDE's, so run them on your systems to explore them .
Comment