0

I have two arrays:

array([2,3,4,4,1])

and

array([3,3,5,4,1])

I want to return the number of similar values at similar index positions. In this case this should be 3, is this possible with a single numpy operation? I know how to do it with a for loop but I rather not do this.

1 Answers1

3

Use np.sum()

l1 = np.array([2, 3, 4, 4, 1])
l2 = np.array([3, 3, 5, 4, 1])

>>> np.sum(l1 == l2)
3

>> l1 == l2
array([False,  True, False,  True,  True])
Corralien
  • 109,409
  • 8
  • 28
  • 52