简体   繁体   English

这些 np.linalg.norm 方法有什么区别

[英]What's the difference between these np.linalg.norm methods

I have these two methods which are from a KNN implementation.我有这两种来自 KNN 实现的方法。 I gather that they are two distance measurements, however I do not understand how they differ.我认为它们是两个距离测量值,但是我不明白它们有何不同。 I've tried looking up the method but haven't had any luck.我试过查找方法,但没有任何运气。

def euclideanDistance(in1,in2):
    return np.linalg.norm(in1-in2)

def L1Distance(in1,in2):
    return np.linalg.norm(in1-in2,1)

The function being called is the same, but in the second case an additional argument is added to change its behaviour.被调用的函数是相同的,但在第二种情况下,添加了一个额外的参数来改变它的行为。

The second keyword argument is order, and if there is no input for this argument it calculates the euclidian Norm sqrt(in1^2 - in2^2).第二个关键字参数是顺序,如果这个参数没有输入,它会计算欧几里得范数 sqrt(in1^2 - in2^2)。

If the ord=1 (your case) the L1 norm is calculated, which is abs(in1 - in2)如果 ord=1(您的情况),则计算 L1 范数,即 abs(in1 - in2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM