# cupy.trace¶

cupy.trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)[source]

Returns the sum along the diagonals of an array.

It computes the sum along the diagonals at axis1 and axis2.

Parameters: a (cupy.ndarray) – Array to take trace. offset (int) – Index of diagonals. Zero indicates the main diagonal, a positive value an upper diagonal, and a negative value a lower diagonal. axis1 (int) – The first axis along which the trace is taken. axis2 (int) – The second axis along which the trace is taken. dtype – Data type specifier of the output. out (cupy.ndarray) – Output array. The trace of a along axes (axis1, axis2). cupy.ndarray