dask 2021.10.0

NotesParametersReturnsBackRef
triu_indices(n, k=0, m=None, chunks='auto')

This docstring was copied from numpy.triu_indices.

Some inconsistencies with the Dask version may exist.

Notes

versionadded

Parameters

n : int

The size of the arrays for which the returned indices will be valid.

k : int, optional

Diagonal offset (see triu for details).

m : int, optional
versionadded

The column dimension of the arrays for which the returned arrays will be valid. By default m is taken equal to n.

Returns

inds : tuple, shape(2) of ndarrays, shape(`n`)

The indices for the triangle. The returned tuple contains two arrays, each with the indices along one dimension of the array. Can be used to slice a ndarray of shape(n, n).

Return the indices for the upper-triangle of an (n, m) array.

See Also

mask_indices

generic function accepting an arbitrary mask function.

tril
tril_indices

similar function, for lower-triangular.

triu

Examples

Compute two different sets of indices to access 4x4 arrays, one for the upper triangular part starting at the main diagonal, and one starting two diagonals further right:

This example is valid syntax, but we were not able to check execution
>>> iu1 = np.triu_indices(4)  # doctest: +SKIP
... iu2 = np.triu_indices(4, 2) # doctest: +SKIP

Here is how they can be used with a sample array:

This example is valid syntax, but we were not able to check execution
>>> a = np.arange(16).reshape(4, 4)  # doctest: +SKIP
... a # doctest: +SKIP array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]])

Both for indexing:

This example is valid syntax, but we were not able to check execution
>>> a[iu1]  # doctest: +SKIP
array([ 0,  1,  2, ..., 10, 11, 15])

And for assigning values:

This example is valid syntax, but we were not able to check execution
>>> a[iu1] = -1  # doctest: +SKIP
... a # doctest: +SKIP array([[-1, -1, -1, -1], [ 4, -1, -1, -1], [ 8, 9, -1, -1], [12, 13, 14, -1]])

These cover only a small part of the whole array (two diagonals right of the main one):

This example is valid syntax, but we were not able to check execution
>>> a[iu2] = -10  # doctest: +SKIP
... a # doctest: +SKIP array([[ -1, -1, -10, -10], [ 4, -1, -1, -10], [ 8, 9, -1, -1], [ 12, 13, 14, -1]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.routines.triu_indices_from dask.array.routines.tril_indices

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /dask/array/routines.py#2465
type: <class 'function'>
Commit: