計算 Python (list or array) 相同索引元素相等的個數

上代碼:spa

a = [2, 3, 3, 1, 1, 3, 3, 3, 2, 1, 3, 1, 3, 2, 2, 2, 3, 1, 2, 3, 2, 3,
       1, 1, 2, 1, 1, 1, 2, 2, 3, 3, 2, 3, 1, 1, 3, 1, 2, 1, 2, 3, 3, 3,
       2, 2, 3, 1, 2, 3, 1, 1, 2, 3, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 3, 3,
       2, 3, 2, 2, 3, 1, 1, 2, 1, 1, 1, 1, 1, 3, 2, 2, 2, 2, 2, 3, 3, 1,
       3, 3, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1]
b = [2, 1, 1, 1, 1, 3, 3, 3, 2, 1, 3, 3, 3, 2, 2, 2, 3, 1, 2, 3, 2, 3,
       1, 3, 2, 1, 1, 1, 2, 3, 3, 1, 2, 3, 1, 1, 1, 3, 2, 1, 2, 3, 3, 3,
       2, 2, 3, 3, 2, 3, 1, 3, 2, 3, 2, 1, 2, 2, 2, 3, 1, 2, 2, 2, 3, 3,
       2, 3, 2, 2, 3, 1, 1, 2, 1, 3, 1, 1, 3, 3, 2, 2, 2, 2, 2, 3, 3, 3,
       3, 3, 3, 3, 2, 1, 3, 1, 2, 1, 3, 3]

import numpy as np
a = np.array(a)
b = np.array(b)
sum(a==b) #個數爲84
相關文章
相關標籤/搜索