计算 Python (list or array) 相同索引元素相等的个数

上代码:

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

 

posted @ 2018-04-26 17:31  Jansora  阅读(9140)  评论(0编辑  收藏  举报