Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
themeEmacs
from math import sin, cos, sqrt, atan2, radians 
# approximate radius of earth in km


def getDistance(_lat1,_lon1,_lat2,_lon2):
    R = 6373.0
  
  lat1 = radians(52.2296756( float(_lat1) )
    lon1 = radians(21.0122287( float(_lon1) ) 
    lat2 = radians(52.406374 float(_lat2) )
    lon2 = radians(16.9251681( float(_lon2) )
    dlon = lon2 - lon1 
    dlat = lat2 - lat1
    
a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
    
c = 2 * atan2(sqrt(a), sqrt(1 - a))
 
   distance = R * c
print("Result:", distance) 
print("Should be:", 278.546, "km")    return distance


dist = getDistance(52.2296756,21.0122287,52.406374,16.9251681)

a=999







문장간 유사도측정(edit distance)

Code Block
languagepy
themeEmacs
def edit_distance(_first , _second):      
    first_len , second = _first.replace(' ','')
    second= _second.replace(' ','') 
    first_len = len(first) ,
    second_len = len(second) 
  
    if first_len > second_len : 
        first , second = second , first 
        first_len , second_len = second_len , first_len 
  
    print(first_len)
    print(second_len) 
    current = range(first_len+1) 
  
    for i in range(1,second_len+1): 
        previous , current = current , [i]+[0]*second_len 
  
        for j in range(1,first_len+1): 
            add , delete = previous[j]+1 , current[j-1]+1 
            change = previous[j-1] 
            if first[j-1] != second[i-1]: 
                change = change + 1 
  
            current[j] = min(add , delete , change) 
  
    return current[first_len] 



sFirstStr = sys.argv[1] 
sSecondStr = sys.argv[2] 
  
sFirst = unicode(sFirstStr,'cp949') 
sSecond = unicode(sSecondStr,'cp949') 


nDistanceValue = edit_distance(sFirst,sSecond) 
  
print(nDistanceValue)