def editdist_np(source, target):
if len(source) < len(target):
return editdist_np(target, source)
if len(target) == 0:
return len(source)
previous_row = np.arange(target.size + 1)
for s in source:
current_row = previous_row + 1
current_row[1:] = np.minimum(current_row[1:], np.add(previous_row[:-1], target != s))
current_row[1:] = np.minimum(current_row[1:], current_row[0:-1] + 1)
previous_row = current_row
return previous_row[-1]
# Pure python version
# from [https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Python, the 6th version]
评论列表
文章目录