File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,17 @@ def hamming_distance(
102
102
103
103
nbits = max (len (bitstring_1 ), len (bitstring_2 ))
104
104
105
- difference = abs (int (bitstring_1 , 2 ) - int (bitstring_2 , 2 ))
105
+ bitstring_1 = "0" * (nbits - len (bitstring_1 )) + bitstring_1
106
+ bitstring_2 = "0" * (nbits - len (bitstring_2 )) + bitstring_2
106
107
107
- return hamming_weight (f"{ difference :{nbits }b} " , return_indexes = return_indexes )
108
+ difference = np .array (list (bitstring_1 ), dtype = int ) - np .array (
109
+ list (bitstring_2 ), dtype = int
110
+ )
111
+ difference = np .abs (difference )
112
+ difference = difference .astype (str )
113
+ difference = "" .join (difference )
114
+
115
+ return hamming_weight (difference , return_indexes = return_indexes )
108
116
109
117
110
118
def hadamard_transform (array , implementation : str = "fast" , backend = None ):
You can’t perform that action at this time.
0 commit comments