NumPy tril preserves a lower triangular region without shortening the matrix
Keeping a lower triangular region is a positional operation, not a way to choose the smallest values in an array. NumPy tril returns a copy with entries above a selected diagonal replaced by zero. Academia Master Trader presents this English lesson for readers in Bahrain, using constructed matrices to explain which positions remain, how offsets move the boundary and why the shape of the result stays unchanged.
The default includes the main diagonal and everything below it
After import numpy as np, define m = np.array([[3,6,9],[12,15,18],[21,24,27]]). The call l = np.tril(m) returns [[3,0,0],[12,15,0],[21,24,27]], with shape (3,3).
The main diagonal entries three, fifteen and twenty seven remain. The entries below them remain too. Positions above that diagonal become zero. With zero based row and column indices, the default retains a position when its column index is no greater than its row index. No comparison between the numeric values is involved.

A negative offset excludes the main diagonal
The call np.tril(m,k=-1) returns [[0,0,0],[12,0,0],[21,24,0]]. The retained boundary is now one diagonal below the main diagonal. The main diagonal itself is outside the retained region and becomes zero.
The entry twenty one remains because the function keeps everything on or below the selected boundary, not only entries exactly on that diagonal. A triangular region can therefore contain several diagonals. State the boundary and the retained side separately when describing the result, especially when a reader expects a single diagonal sequence.
A positive offset allows more positions above the main diagonal
The call np.tril(m,k=1) returns [[3,6,0],[12,15,18],[21,24,27]]. The first diagonal above the main one now belongs to the retained region. Only the entry nine is replaced by zero in this example.
A positive k does not turn tril into an upper triangle operation. The selected boundary moves upward, but the function still retains positions on or below it. Read the sign as an offset from the main diagonal, not as a direction in which values are sorted or moved. Entries that remain keep their original positions.
Rectangular matrices keep their shape
Define a = np.array([[1,2,3],[4,5,6]]), with shape (2,3). The call np.tril(a) returns [[1,0,0],[4,5,0]], also with shape (2,3). The input does not need to be square.
The operation replaces values rather than removing rows, columns or individual positions. An output zero can be a replacement or an original zero that was retained. Keep the positional rule beside the result when the distinction matters. Output shape alone cannot reveal which entries were replaced.
Copies and higher dimensional slices are separate concerns
NumPy documents the result as a copy with the same shape and data type as the input. Writing l[1,0] = 99 changes the returned array while m[1,0] remains twelve. The original matrix is not overwritten by the call.
For input with more than two dimensions, the rule applies to the final two axes. With b = np.array([[[1,2],[3,4]],[[5,6],[7,8]]]), the result is [[[1,0],[3,4]],[[5,0],[7,8]]]. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the offset and the affected axes without confusing triangular replacement with diagonal extraction or summation.