各ビット文字列の長さが1280で、200万近くのビット文字列を持つnumpy配列でハミング距離を計算するときに、計算時間を短縮しようとしています。
私の現在の実装には約 4 秒近くかかりますが、これは私の場合にはかなり悪いことです。私の現在のアプローチ:
>>> A = np.array(['00000000000000000000000000000000000000000000000001101110000000000000000000000000000000000000000100011000100001000000000000000100011110101111011110000000000000000000000000000000000000001000000000000000000000000000001001100011000110000000000000000000000000000100000000000000000000000010000000000000000000100000000000000000000000000000100011000010000000000000010001100001000000000000001000011000110000000010000000001000010000100000000000000100001000010000000000000010000110001100000001100001000000000100001000010000100001000010000100000000000000000000000000000000001000010000100001000110000100011000010000100001000000000000000000000000000000000000000100011000010000100001000010000100001000000000000000000000000000000000000000000001000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'])
>>> A = A.repeat(2000000,axis=0)
>>> B = A
>>> A.shape
(2000000,)
>>> B.shape
(2000000,)
>>> first=(np.fromstring(A, dtype=np.uint8)-48).reshape(-1,1280)
>>> second=(np.fromstring(B, dtype=np.uint8)-48).reshape(-1,1280)
>>> hamm_dist = (first!=second).sum(1)
>>> hamm_dist.shape
(2000000,)
計算時間を 1 秒未満またはそれ以上に短縮できる高速な方法はありますか?