Trace
Shippingmatrix_traceSum of the diagonal, tr(A) = Σ Aᵢᵢ
Signature
Inputs
aSignal|Arrayrequired— A 2-D matrix.
Outputs
traceScalar— The trace $\operatorname{tr}(A) = \sum_i A_{ii}$.
Description
Trace returns the sum of the main-diagonal entries of a matrix, , via the MKL LAPACK-backed toolkit. The trace equals the sum of the eigenvalues and is invariant under similarity transforms and cyclic permutations, which makes it a lightweight invariant for checking decompositions and computing quantities like the sum of variances of a covariance matrix.
The input is read as a 2-D matrix; the result is a dimensionless Scalar.
Mathematics
Examples
Trace equals eigenvalue sum
For , the trace output is — which also equals the sum of 's eigenvalues, a handy cross-check against matrix_eigh.
Applications
- Summing variances (total variance) from a covariance matrix's diagonal.
- Cheap invariant to validate eigen-decompositions (trace = Σλ).
- Computing quadratic-form and quantum-mechanical expectation traces.
- Sanity-checking similarity transforms, which preserve the trace.
Neat
The trace is a similarity invariant, so it survives change-of-basis untouched — a $O(n)$ check on an $O(n^3)$ decomposition.
It equals the eigenvalue sum, giving a free consistency test against matrix_eig / matrix_eigh.
Known issues
Defined only for the main diagonal of a 2-D matrix — for a general axis sum use tensor_reduce or einsum.
A non-square matrix's diagonal sum is well-defined but rarely meaningful; trace is intended for square inputs.