检查有多少元素有两种numpy的数组等于蟒 [英] check how many elements are equal in two numpy arrays python

查看:118
本文介绍了检查有多少元素有两种numpy的数组等于蟒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些(长度相同)二numpy的数组,我要统计有多少元素是这两个阵列(等于=相同的价值与地位的数组)之间的平等

I have two numpy arrays with number (Same length), and I want to count how many elements are equal between those two array (equal = same value and position in array)

A = [1, 2, 3, 4]
B = [1, 2, 4, 3]

然后我想返回值是2(仅1和2是地位和价值相等​​)

then I want the return value to be 2 (just 1&2 are equal in position and value)

推荐答案

使用<一个href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html\"><$c$c>numpy.sum:

>>> import numpy as np
>>> a = np.array([1, 2, 3, 4])
>>> b = np.array([1, 2, 4, 3])
>>> np.sum(a == b)
2
>>> (a == b).sum()
2

这篇关于检查有多少元素有两种numpy的数组等于蟒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆