dask 2021.10.0

ParametersReturns
trace(a, offset=0, axis1=0, axis2=1, dtype=None)

This docstring was copied from numpy.trace.

Some inconsistencies with the Dask version may exist.

If a is 2-D, the sum along its diagonal with the given offset is returned, i.e., the sum of elements a[i,i+offset] for all i.

If a has more than two dimensions, then the axes specified by axis1 and axis2 are used to determine the 2-D sub-arrays whose traces are returned. The shape of the resulting array is the same as that of a with :None:None:`axis1` and :None:None:`axis2` removed.

Parameters

a : array_like

Input array, from which the diagonals are taken.

offset : int, optional

Offset of the diagonal from the main diagonal. Can be both positive and negative. Defaults to 0.

axis1, axis2 : int, optional

Axes to be used as the first and second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults are the first two axes of a.

dtype : dtype, optional

Determines the data-type of the returned array and of the accumulator where the elements are summed. If dtype has the value None and a is of integer type of precision less than the default integer precision, then the default integer precision is used. Otherwise, the precision is the same as that of a.

out : ndarray, optional (Not supported in Dask)

Array into which the output is placed. Its type is preserved and it must be of the right shape to hold the output.

Returns

sum_along_diagonals : ndarray

If a is 2-D, the sum along the diagonal is returned. If a has larger dimensions, then an array of sums along diagonals is returned.

Return the sum along diagonals of the array.

See Also

diag
diagflat
diagonal

Examples

This example is valid syntax, but we were not able to check execution
>>> np.trace(np.eye(3))  # doctest: +SKIP
3.0
This example is valid syntax, but we were not able to check execution
>>> a = np.arange(8).reshape((2,2,2))  # doctest: +SKIP
... np.trace(a) # doctest: +SKIP array([6, 8])
This example is valid syntax, but we were not able to check execution
>>> a = np.arange(24).reshape((2,2,2,3))  # doctest: +SKIP
... np.trace(a).shape # doctest: +SKIP (2, 3)
See :

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/reductions.py#1595
type: <class 'function'>
Commit: