This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

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 : int

The row dimension of the array.

offset : int, optional

Diagonal offset; 0 (default) is the main diagonal. Corresponds to k in numpy.triu_indices.

m : int, optional

The column dimension. If None (default), assumed equal to n.

device : Device, optional

The device on which to place the returned arrays. Default: current device.

xp : array_namespace

The standard-compatible namespace to create the indices in.

Returns

: tuple of array

Row and column indices (rows, cols) of the upper triangle of the (n, m) matrix, shifted by offset.

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