bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / tri
_ArrayFunctionDispatcher
numpy:tri
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_twodim_base_impl.py:389
Signature
def tri(N, M = None, k = 0, dtype = <class 'float'>, *, like = None)Summary
An array with ones at and below the given diagonal and zeros elsewhere.
Parameters
N: intNumber of rows in the array.
M: int, optionalNumber of columns in the array. By default,
Mis taken equal toN.k: int, optionalThe sub-diagonal at and below which the array is filled.
k= 0 is the main diagonal, whilek< 0 is below it, andk> 0 is above. The default is 0.dtype: dtype, optionalData type of the returned array. The default is float.
like: array_like, optionalReference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as
likesupports the__array_function__protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.
Returns
tri: ndarray of shape (N, M)Array with its lower triangle filled with ones and zero elsewhere; in other words
T[i,j] == 1forj <= i + k, 0 otherwise.
Examples
import numpy as np np.tri(3, 5, 2, dtype=int)✓
array([[1, 1, 1, 0, 0],
[1, 1, 1, 1, 0],
[1, 1, 1, 1, 1]])
np.tri(3, 5, -1)
✗array([[0., 0., 0., 0., 0.],
[1., 0., 0., 0., 0.],
[1., 1., 0., 0., 0.]])
Aliases
numpy.trinumpy.lib._twodim_base_impl._tri_with_like