美文网首页
python-ML学习小记-L1-距离计算

python-ML学习小记-L1-距离计算

作者: 李大狗随随便便地 | 来源:发表于2016-12-20 22:19 被阅读0次

class Distance(object):

    staticmethod

    def cMDistance(self,vector1,vector2,q=1):

        distance=0

        n=len(vector1)

        for i in range(n):

            distance +=pow(abs(vector1[i]-vector2[i]),q)

         return round(pow(distance,1.0/q),5)

    staticmethod

    def cEDistance(self,vector1,vector2):

        return Distance.cMDistance(self,vector1,vector2,2)

相关文章

网友评论

      本文标题:python-ML学习小记-L1-距离计算

      本文链接:https://www.haomeiwen.com/subject/bymfvttx.html