I'm trying to compare two 3-dimensional arrays and count how many inner arrays are equal.
I'm comparing 2 patches of a picture and want to know how many pixels are equal and not how many color values are equal. And it would be nice if it's efficient so I'm using numpy. I know how to make the comparison with for loops but it's too slow.
But I'm only able to count it element wise, here's my snippet:
import numpy as np
a = np.array([[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255]],
[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255]],
[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255]],
[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255]]])
b = np.array([[[255, 255, 255],
[255, 255, 255],
[0, 0, 0],
[0, 0, 0]],
[[255, 255, 255],
[255, 255, 255],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]])
print(np.sum(a[:, :] == b[:, :]))
# prints 12 and i would like to have a 4 in this example