假设我有以下向量x
的数组,其中可能的值为0,1,2:
import numpy as np
x = np.random.randint(0,3,(10,5), dtype=np.int8)
我想对汉明距离为零或一的所有向量进行相似性匹配,其中匹配规则为:
1. 0 == 0 and 1 == 1 i.e. hamming distance is 0
2. 2 match both 1 and 0 i.e. hamming distance is 0
3. otherwise Hamming distance is 1
即找到一些会返回的算术运算:
0 x 0 = 0
1 x 1 = 0
0 x 1 = 1
1 x 0 = 1
0 x 2 = 0
1 x 2 = 0
并且我的输出应该是每个矢量(行)x
和任意矢量z
之间的汉明距离]]
z = np.random.randint(0,2,5)
np.sum(np.add(x,z) == 1, axis=1)
假设我有以下向量x数组,其中可能的值为0,1,2:以num x的形式导入numpy x = np.random.randint(0,3,(10,5),dtype = np。 int8)我想对所有...进行相似性匹配...
int(x+y == 1)
这不行吗?