code: import numpy as np
  from operator import truediv
  
  
  def AA_andEachClassAccuracy(confusion_matrix):
      counter = confusion_matrix.shape[0]
      list_diag = np.diag(confusion_matrix)  # 对角线
      list_raw_sum = np.sum(confusion_matrix, axis=1)
      each_acc = np.nan_to_num(truediv(list_diag, list_raw_sum))
      average_acc = np.mean(each_acc)
      return each_acc, average_acc
  
apis: numpy.sum numpy.mean numpy.diag