有关python,numexpr和数组运算加速的应用求助
发布网友
发布时间:2022-05-31 04:33
我来回答
共1个回答
热心网友
时间:2023-10-09 05:09
from math import radians, cos, sin, asin, sqrt
import numpy as np
import numexpr as ne
def geodistance(lng1,lat1,lng2,lat2): #定义geodistance为运算两点经纬度间的距离为多少米的函数
lng1,lat1,lng2,lat2=list(map(lambda x:list(map(radians,x)) ,[lng1, lat1, lng2, lat2]))
dlon=[x-y for x,y in zip(lng2,lng1)]
dlat=[x-y for x,y in zip(lat2,lat1)]
a=[sin(a/2)**2+cos(b)*cos(c)*sin(d/2)**2 for a,b,c,d in zip(dlat, lat1, lat2, dlon)]
dis=[2*i*sin(sqrt(i))*6371*1000 for i in a]
return dis
lng1=np.arange(0,180,0.0001)
lat1=np.arange(0,180,0.0001)
lng2=np.arange(180,360,0.0001)
lat2=np.arange(180,360,0.0001)
a=geodistance(lng1,lat1,lng2,lat2)