我在github https://gist.github.com/StuartGordonReid/90c8301f9403707a22ff上找到了这个模块,它实现了一些字符串相似性方法。我是python的新手,我在使用de manhattan_distance功能时遇到了一些麻烦。该函数的代码是:
def manhattan_distance(self, p_vec, q_vec):
"""
This method implements the manhattan distance metric
:param p_vec: vector one
:param q_vec: vector two
:return: the manhattan distance between vector one and two
"""
return max(np.sum(np.fabs(p_vec - q_vec)), self.e)
但是当试图使用这个功能时(类似这样)
t = similarity.Similarity(1)
t.manhattan_distance(np.array(["this is a testee"]), np.array(["this is a test"]))
或:
vector_one = ["this", "is", "a", "test"]
vector_two = ["this", "is", "a", "testee"]
t.manhattan_distance(vector_one, vector_two)
我收到以下错误:
TypeError:ufunc'减去'不包含带有签名匹配类型的循环dtype(' S16')dtype(' S16')dtype(' S16')