Minkowski 거리는 미터법이며 표준 벡터 공간에서 결과는 Minkowski 부등식입니다. Minkowski 거리는 벡터의 거리 유사도에 사용됩니다.
scipy.spatial.distance.minkowski
>>> from scipy.spatial import distance >>> distance.minkowski([1, 0, 0], [0, 1, 0], 1) 2.0 >>> distance.minkowski([1, 0, 0], [0, 1, 0], 2) 1.4142135623730951 >>> distance.minkowski([1, 0, 0], [0, 1, 0], 3) 1.2599210498948732 >>> distance.minkowski([1, 1, 0], [0, 1, 0], 1) 1.0 >>> distance.minkowski([1, 1, 0], [0, 1, 0], 2) 1.0 >>> distance.minkowski([1, 1, 0], [0, 1, 0], 3) 1.0
예시 코드
from math import * from decimal import Decimal def my_p_root(value, root): my_root_value = 1 / float(root) return round (Decimal(value) ** Decimal(my_root_value), 3) def my_minkowski_distance(x, y, p_value): return (my_p_root(sum(pow(abs(a-b), p_value) for a, b in zip(x, y)), p_value)) # Driver Code vector1 = [0, 2, 3, 4] vector2 = [2, 4, 3, 7] my_position = 5 print("The Distance is::",my_minkowski_distance(vector1, vector2, my_position))
출력
The Distance is:: 3.144