Shai Zarzewski - 1 year ago 251

Python Question

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]

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

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Using `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
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**