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 / diag_indices

function

scipy._external.array_api_extra._delegation:diag_indices

source: build-install/usr/lib/python3.14/site-packages/scipy/_external/array_api_extra/_delegation.py:420

Signature

def diag_indices(n: int, /, ndim: int = 2, device: Device | None = None, xp: ArrayNamespace) → tuple[Array, ...]

Summary

Return the indices to access the main diagonal of an array.

Extended Summary

Equivalent to numpy.diag_indices.

Parameters

n : int

The size of each dimension of the (hyper-)cube (n, n, ..., n) that the returned indices index into.

ndim : int, optional

The number of dimensions. Default: 2.

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

1-D integer arrays of length n that together index the main diagonal of an array of shape (n,) * ndim.

Examples

import array_api_strict as xp
import array_api_extra as xpx
rows, cols = xpx.diag_indices(3, xp=xp)
rows
cols
⚠
Traceback (most recent call last):
  File "<doctest scipy._external.array_api_extra._delegation:diag_indices[0]>", line 1, in <module>
    cols
NameError: name 'cols' is not defined

Aliases

  • scipy.differentiate.xpx.diag_indices