flopscope.numpy.diag_indices_from
fnp.diag_indices_from(arr)[flopscope source][numpy source]
Return the indices to access the main diagonal of an n-dimensional array.
Adapted from NumPy docs np.diag_indices_from
Cost
0
Flopscope Context
Return indices to access main diagonal of given array.
See diag_indices for full details.
Parameters
- arr:array, at least 2-D
See also
Examples
>>> import flopscope.numpy as fnpCreate a 4 by 4 array.
>>> a = flops.arange(16).reshape(4, 4)
>>> a
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]])Get the indices of the diagonal elements.
>>> di = flops.diag_indices_from(a)
>>> di
(array([0, 1, 2, 3]), array([0, 1, 2, 3]))>>> a[di]
array([ 0, 5, 10, 15])This is simply syntactic sugar for diag_indices.
>>> flops.diag_indices(a.shape[0])
(array([0, 1, 2, 3]), array([0, 1, 2, 3]))