描述: 下面的代码接收n维的两个点的坐标。它计算论文的manhanttan距离的两个点 的代码:python中的两个代码应该给出相同的结果,但它们不包含
def manhanttan(ponto1, ponto2):
totalp1 = 0
totalp2 = 0
for x in range(0, len(ponto1)):
totalp1 += ponto1[x]
totalp2 += ponto2[x]
return abs(totalp1 - totalp2)
和
def manhanttan(ponto1, ponto2):
total = 0
for x in range(0, len(ponto1)):
total += abs(ponto1[x] - ponto2[x])
return total
是给不同的结果,我不知道为什么。有人能帮助我吗?
PS:在列表中的所有值都是阳性
PS2:与第一个我的分类得到
K1: Expected Class: 6, Found Class: 0 K2: Expected Class: 6, Found Class: 0 K3: Expected Class: 6, Found Class: 0 K4: Expected Class: 6, Found Class: 0 K5: Expected Class: 6, Found Class: 0
,并与其他我得到 K1: Expected Class: 6, Found Class: 6 K2: Expected Class: 6, Found Class: 6 K3: Expected Class: 6, Found Class: 6 K4: Expected Class: 6, Found Class: 6 K5: Expected Class: 6, Found Class: 6
(NB:您的代码片断混合制表符和空格,它不应该) – user3666197 2014-10-29 16:31:46
因为它们实现两个不同的东西.... 考虑P1 = [-2,2] P2 = [0,0] – igon 2014-10-29 16:32:39
丝毫什么输入你得到不同的结果? – Kasramvd 2014-10-29 16:33:48