假设我有以下向量数组x
,其中可能的值是0,1,2:
import numpy as np
x = np.random.randint(0,3,(10,5), dtype=np.int8)
我想对汉明距离为0或1的所有向量进行相似性匹配,匹配规则如下:
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 = np.random.randint(0,2,5)
np.sum(np.add(x,z) == 1, axis=1)
这不管用吗?你知道吗
或者如果你想两边都有两个
这个问题有什么我遗漏的吗???你知道吗
相关问题 更多 >
编程相关推荐