bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / _external / array_api_extra / _delegation / triu_indices
function
scipy._external.array_api_extra._delegation:triu_indices
source: build-install/usr/lib/python3.14/site-packages/scipy/_external/array_api_extra/_delegation.py:1600
Signature
def triu_indices(n: int, /, offset: int = 0, m: int | None = None, device: Device | None = None, xp: ArrayNamespace) → tuple[Array, Array]Summary
Return the indices of the upper triangle of an (n, m) array.
Extended Summary
Equivalent to numpy.triu_indices with parameter k renamed to offset to match array_api.linalg.diagonal's naming.
Parameters
n: intThe row dimension of the array.
offset: int, optionalDiagonal offset;
0(default) is the main diagonal. Corresponds tokin numpy.triu_indices.m: int, optionalThe column dimension. If
None(default), assumed equal ton.device: Device, optionalThe device on which to place the returned arrays. Default: current device.
xp: array_namespaceThe standard-compatible namespace to create the indices in.
Returns
: tuple of arrayRow and column indices
(rows, cols)of the upper triangle of the(n, m)matrix, shifted byoffset.
Notes
The generic fallback uses array_api.nonzero, so namespaces without nonzero are not supported on that path.
Examples
import array_api_strict as xp import array_api_extra as xpx rows, cols = xpx.triu_indices(3, xp=xp) rows cols⚠
Traceback (most recent call last):
File "<doctest scipy._external.array_api_extra._delegation:triu_indices[0]>", line 1, in <module>
cols
NameError: name 'cols' is not defined
Aliases
scipy.differentiate.xpx.triu_indices