mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-21 20:45:10 +00:00
code style Update Phpml\Math\Distance\Manhattan::distance() method. (#154)
I think this will be better.
This commit is contained in:
parent
f7537c049a
commit
ff80af2044
@ -18,13 +18,8 @@ class Manhattan implements Distance
|
||||
throw InvalidArgumentException::arraySizeNotMatch();
|
||||
}
|
||||
|
||||
$distance = 0;
|
||||
$count = count($a);
|
||||
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$distance += abs($a[$i] - $b[$i]);
|
||||
}
|
||||
|
||||
return $distance;
|
||||
return array_sum(array_map(function ($m, $n) {
|
||||
return abs($m - $n);
|
||||
}, $a, $b));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user