y = np.matrix(x)
a = y ** 3
b = np.linalg.matrix_power(x, 3)
print(a)
print(b)
assert np.all(a == b)
How to raise a numpy array to a power? (corresponding to repeated matrix multiplications, not elementwise)