Trace properties of square matrices

import numpy as np # A, B, C - square matrices A = np.array([ [4, 8, 7, 9], [6, 3, 7, 5], [2, 4, 4, 2], [5, 8, 6, 4] ]) B = np.array([ [1, 3, 5, 7], [3, 4, 5, 6], [4, 6, 8, 10], [5, 6, 7, 8] ]) C = np.array([ [4, 3, 0, 1], [4, 2, 3, 3], [4, 1, 6, 5], [4, 0, 9, 7] ]) tr = np.trace eigvals, eigvecs = np.linalg.eig(A) detA = np.linalg.det(A) rankA = np.linalg.matrix_rank(A) assert tr(A + B) == tr(A) + tr(B) assert tr(A * B) == tr(B * A) assert tr(A*B*C) == tr(B*C*A) == tr(C*A*B) assert tr(A) == np.sum(eigvals) assert np.allclose(detA, np.prod(eigvals)) assert rankA == len(np.nonzero(eigvals)[0])