Iai*_*ing 16
这是一个简单的方法
n = 10
x = rand(n)
y = rand(n)
d = norm(x-y) # The euclidean (L2) distance
Run Code Online (Sandbox Code Playgroud)
对于曼哈顿/出租车/ L1距离,请使用 norm(x-y,1)
Job*_*Job 13
由于可爱的距离套餐,这很容易做到:
Pkg.add("Distances") #if you don't have it
using Distances
one7d = rand(7)
two7d = rand(7)
dist = euclidean(one7d,two7d)
Run Code Online (Sandbox Code Playgroud)
此外,如果你说2个9d col矢量矩阵,你可以使用colwise得到每个相应对之间的距离:
thousand9d1 = rand(9,1000)
thousand9d2 = rand(9,1000)
dists = colwise(Euclidean(), thousand9d1, thousand9d2)
#returns: 1000-element Array{Float64,1}
Run Code Online (Sandbox Code Playgroud)
您还可以比较单个矢量,例如原点(如果您想要每个列矢量的大小)
origin9 = zeros(9)
mags = colwise(Euclidean(), thousand9ds1, origin9)
#returns: 1000-element Array{Float64,1}
Run Code Online (Sandbox Code Playgroud)
其他距离也可用:
有关详细信息,请参阅包的github页面.