Explore Library
Code QuizIntermediate

Trace of a Matrix

Find the mistake in a hand-rolled matrix trace calculation.

Codepython
import numpy as np

M = np.array([[1, 2],
              [3, 4]])
# Trace = sum of diagonal elements
trace = M[0][0] + M[1][0]
print(trace)

What is the bug in this code?