In short, the two results will differ when the classes don’t all have
the same number of samples (and some other conditions that
aren’t the main point).

In [1] you are calculating the number of correct predictions
(regardless of the specific class) divided by the total number
of predictions. This is what I would typically call “accuracy.”

In [2] you are calculating the accuracy for each class separately,
and then taking the mean of those class accuracies. This is
not the same.

To see this, consider a case where you have two classes, but
class A has 1000 samples and class B has 10 samples. Let’s
say you get all 1000 class A predictions wrong and get all 10
class B predictions right. Your overall accuracy ([1]) will be 10 / 1010, which is about 1%. But your class A accuracy is
0% and your class B accuracy is 100%, so averaging those
accuracies over the two classes will give you 50%.