I want to calculate the pairwise hamming distance of a 2D numpy array.
My arrays is
A
array([[-1, 0, -1, 0, -1, 0],
[ 1, 0, 0, 0, 0, 0],
[ 0, 0, 1, 1, 1, 0],
[ 0, 0, -1, 1, 0, 0],
[ 0, 0, 0, 0, -1, 0]], dtype=int8)
I want to calculate the hamming distance between the rows of A, but considering only non-zero values. If one of the entry is zero, we dont include it in calculation.
My output should be
B
array([[0, 1, 2, 0, 0],
[1, 0, 0, 0, 0],
[2, 0, 0, 1, 1],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0]], dtype=int8)