bundles / numpy latest / numpy / tril_indices
function
numpy:tril_indices
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_twodim_base_impl.py :907
Signature
def tril_indices ( n , k = 0 , m = None ) Summary
Return the indices for the lower-triangle of an (n, m) array.
Parameters
n: intThe row dimension of the arrays for which the returned indices will be valid.
k: int, optionalDiagonal offset (see
trilfor details).m: int, optionalThe column dimension of the arrays for which the returned arrays will be valid. By default
mis taken equal ton.
Returns
inds: tuple of arraysThe row and column indices, respectively. The row indices are sorted in non-decreasing order, and the corresponding column indices are strictly increasing for each row.
Examples
import numpy as np
✓il1 = np.tril_indices(4) il1✓
a = np.arange(16).reshape(4, 4) a✓
a[il1]
✓a[il1] = -1 a✓
il2 = np.tril_indices(4, 2) a[il2] = -10 a✓
See also
- mask_indices
generic function accepting an arbitrary mask function.
- tril
- triu
- triu_indices
similar function, for upper-triangular.
Aliases
-
numpy.tril_indices