mlx.core.trace#
- trace(a: array, /, offset: int = 0, axis1: int = 0, axis2: int = 1, dtype: Dtype | None = None, *, stream: None | Stream | Device = None) array #
Return the sum along a specified diagonal in the given array.
- Parameters:
a (array) – Input array
offset (int, optional) – Offset of the diagonal from the main diagonal. Can be positive or negative. Default:
0
.axis1 (int, optional) – The first axis of the 2-D sub-arrays from which the diagonals should be taken. Default:
0
.axis2 (int, optional) – The second axis of the 2-D sub-arrays from which the diagonals should be taken. Default:
1
.dtype (Dtype, optional) – Data type of the output array. If unspecified the output type is inferred from the input array.
- Returns:
Sum of specified diagonal.
- Return type: