I'm trying to implement vectorization for answer from this question
Fastest way to get hamming distance for integer array
r = (1 << np.arange(64, dtype=np.uint64))[:, None]
def hamming_distance_v2(a, b):
t = np.bitwise_xor(a, b)
p = np.bitwise_and(t, r)
return np.count_nonzero(p != 0)
I want to pass an 2d array as first parameter, for example
a = [[127,255], [127,255]]
b = [127,240]
hamming_distance_v1(a, b) -> [4,4]
If 2d array as first argument is used, the following error is returned:
ValueError: unable to broadcast argument 1 to output array
Is there a way to implement vectorization on current realization of hamming distance or some other ways to count this distance between 2d and 1d arrays?