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, 16, 6, 41), 'numpy.diag', 'np.diag', ({(6, 24, 6, 40): 'confusion_matrix'}, {}), '(confusion_matrix)', True, 'import numpy as np\n'), ((7, 19, 7, 51), 'numpy.sum', 'np.sum', (), '', True, 'import numpy as np\n'), ((9, 18, 9, 35), 'numpy.mean', 'np.mean', ({(9, 26, 9, 34): 'each_acc'}, {}), '(each_acc)', True, 'import numpy as np\n'), ((8, 29, 8, 61), 'operator.truediv', 'truediv', ({(8, 37, 8, 46): 'list_diag', (8, 48, 8, 60): 'list_raw_sum'}, {}), '(list_diag, list_raw_sum)', False, 'from operator import truediv\n')]