This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / diag_indices_from

_ArrayFunctionDispatcher

numpy:diag_indices_from

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_index_tricks_impl.py :997

Signature

def   diag_indices_from ( arr )

Summary

Return the indices to access the main diagonal of an n-dimensional array.

Extended Summary

See diag_indices for full details.

Parameters

arr : array, at least 2-D

Examples

import numpy as np
Create a 4 by 4 array.
a = np.arange(16).reshape(4, 4)
a
Get the indices of the diagonal elements.
di = np.diag_indices_from(a)
di
a[di]
This is simply syntactic sugar for diag_indices.
np.diag_indices(a.shape[0])

See also

diag_indices

Aliases

  • numpy.diag_indices_from