difference - Two codes in python should be giving the same result but they don't -



difference - Two codes in python should be giving the same result but they don't -

description: next codes recieves coordinates of 2 dots n dimensions. calculates manhanttan distance of theses 2 dots codes:

def manhanttan( ponto1, ponto2 ): totalp1 = 0 totalp2 = 0 x in range( 0, len( ponto1 ) ): totalp1 += ponto1[x] totalp2 += ponto2[x] homecoming abs( totalp1 - totalp2 )

and

def manhanttan( ponto1, ponto2 ): total = 0 x in range( 0, len( ponto1 ) ): total += abs( ponto1[x] - ponto2[x] ) homecoming total

are giving different results , don't know why. can help me?

ps: values in lists positives

ps2: first 1 classifications gets

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

and other 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

your sec function calculating manhattan distance between 2 vectors, i.e. sum of how far apart each individual dimension is. first function reduces each vector single number before taking difference; assuming coordinates positive, means takes manhattan distance origo each vector, takes difference of those. that's different function!

consider pair of 2d vectors:

y 5 4 3 2 b 1 0 o 0 1 2 3 4 5 x

here have origo @ (0,0), @ (1,5) , b @ (4,2). b, need move b-a=(4-1,2-5)=(3,-3), total of sum(map(abs,[3,-3]))=6 steps. getting o 6 steps, , o b likewise, reduction first method considers , b equal, though happen on same distance line running through (6,0) , (0,6) (because manhattan distance equivalent of circle rhombus, 45° rotated square).

python difference absolute-value

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -