首页 > 解决方案 > 如何在python中对LCSS使用递归

问题描述

CSS

我的代码

def Distance(P1,P2,R=6378137):#
    lon1=P1[1];lon2=P2[1]
    lat1=P1[0];lat2=P2[0]
    dist =  R*math.acos(1-(math.pow((math.sin((90-lat1)*math.pi/180)*math.cos(lon1*math.pi/180)-math.sin((90-lat2)*math.pi/180)*math.cos(lon2*math.pi/180)),2)\
                         +math.pow((math.sin((90-lat1)*math.pi/180)*math.sin(lon1*math.pi/180)-math.sin((90-lat2)*math.pi/180)*math.sin(lon2*math.pi/180)),2)\
                         +math.pow((math.cos((90-lat1)*math.pi/180)-math.cos((90-lat2)*math.pi/180)),2))/2)
    return round(dist,2)

def LCSS(A,B,e=500,f=5):
    if len(A)*len(B)==0:
        return 0
    elif Disance(A[-1],B[-1)<e and abs(len(A)-len(B))<f:
        return LCSS()+1
    else:
        return max(LCSS(A[:-1],B),LCSS(A,B[:-1]))

问题
我不知道 LCSS 的功能,因为该功能一直在我的代码中运行,而不是返回 N(int) < max(len(A),len(B))。
谢谢!

标签: pythonpython-3.xrecursion

解决方案


推荐阅读