bundles / numpy latest / numpy / triu_indices
function
numpy:triu_indices
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_twodim_base_impl.py :1054
Signature
def triu_indices ( n , k = 0 , m = None ) Summary
Return the indices for the upper-triangle of an (n, m) array.
Parameters
n: intThe size of the arrays for which the returned indices will be valid.
k: int, optionalDiagonal offset (see
triufor 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, shape(2) of ndarrays, shape(`n`)The 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
✓iu1 = np.triu_indices(4) iu1✓
a = np.arange(16).reshape(4, 4) a✓
a[iu1]
✓a[iu1] = -1 a✓
iu2 = np.triu_indices(4, 2) a[iu2] = -10 a✓
See also
- mask_indices
generic function accepting an arbitrary mask function.
- tril
- tril_indices
similar function, for lower-triangular.
- triu
Aliases
-
numpy.triu_indices