tril_indices(n, k=0, m=None)
The row dimension of the arrays for which the returned indices will be valid.
Diagonal offset (see tril
for details).
The column dimension of the arrays for which the returned arrays will be valid. By default m
is taken equal to n
.
The indices for the triangle. The returned tuple contains two arrays, each with the indices along one dimension of the array.
Return the indices for the lower-triangle of an (n, m) array.
mask_indices
generic function accepting an arbitrary mask function.
triu_indices
similar function, for upper-triangular.
Compute two different sets of indices to access 4x4 arrays, one for the lower triangular part starting at the main diagonal, and one starting two diagonals further right:
>>> il1 = np.tril_indices(4)
... il2 = np.tril_indices(4, 2)
Here is how they can be used with a sample array:
>>> a = np.arange(16).reshape(4, 4)
... a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]])
Both for indexing:
>>> a[il1] array([ 0, 4, 5, ..., 13, 14, 15])
And for assigning values:
>>> a[il1] = -1
... a array([[-1, 1, 2, 3], [-1, -1, 6, 7], [-1, -1, -1, 11], [-1, -1, -1, -1]])
These cover almost the whole array (two diagonals right of the main one):
>>> a[il2] = -10See :
... a array([[-10, -10, -10, 3], [-10, -10, -10, -10], [-10, -10, -10, -10], [-10, -10, -10, -10]])
The following pages refer to to this document either explicitly or contain code examples using this.
numpy.mask_indices
numpy.tril_indices_from
dask.array.routines.tril_indices
numpy.triu_indices
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