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
[(6, 'numpy.diag', 'np.diag', True, 'import numpy as np\n'), (7, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (9, 'numpy.mean', 'np.mean', True, 'import numpy as np\n'), (8, 'operator.truediv', 'truediv', False, 'from operator import truediv\n')]