NumPy tri fills a lower triangular region with ones while preserving the requested rectangle
A triangular pattern can describe which positions belong to a lower region of a matrix. NumPy tri constructs that pattern using ones and zeros. Academia Master Trader presents this English lesson for readers in the Democratic Republic of the Congo, using small constructed arrays to explain dimensions, diagonal offsets and the difference between creating a pattern and selecting existing values.
The default region includes the main diagonal
After import numpy as np, the call np.tri(3,dtype=int) returns [[1,0,0],[1,1,0],[1,1,1]]. The first argument sets the number of rows. Because no column count is supplied, the result is square with shape (3,3).
Ones appear on the main diagonal and below it. Zeros appear above the main diagonal. The first row contains one one, the second row contains two and the third row contains three.
These entries are created from a positional rule. Tri does not read another matrix and preserve its lower entries. It constructs a new array whose values describe membership in the selected region.

A second size argument sets the column count
The call np.tri(3,4,dtype=int) returns [[1,0,0,0],[1,1,0,0],[1,1,1,0]]. Its shape is (3,4): three rows and four columns.
The rectangular boundary and the diagonal boundary are different constraints. The fourth column exists, but none of its positions falls inside this particular lower region. It therefore contains zeros throughout.
Reversing the sizes would create four rows and three columns instead. Write the intended row and column counts before reasoning about which positions contain ones.
A positive offset expands the region upwards
The call np.tri(3,4,k=1,dtype=int) returns [[1,1,0,0],[1,1,1,0],[1,1,1,1]]. The boundary moves to the diagonal immediately above the main diagonal, and the region at and below it is filled with ones.
The call np.tri(3,4,k=-1,dtype=int) returns [[0,0,0,0],[1,0,0,0],[1,1,0,0]]. Here the boundary lies one diagonal below the main diagonal, so the main diagonal itself contains zeros.
Both calls retain shape (3,4). The offset changes the filled region, not the array dimensions. No values wrap around an edge, and a row can contain no ones when the boundary begins below it.
Coordinates state the rule precisely
With zero-based indices, position (i,j) contains one when j <= i+k; otherwise it contains zero. This condition works for rectangular arrays as well as square ones.
The examples request dtype=int for integer entries. The documented default is floating point, and dtype=bool can represent the same region with true and false entries. Changing the data type does not change the boundary coordinates.
Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Keep the shape, offset and coordinate condition beside every triangular pattern so its meaning remains clear.