<p>这看起来是您的理想资源(它们以各种格式为英国的每个邮政编码提供lat和long值):<a href="https://www.freemaptools.com/download-uk-postcode-lat-lng.htm" rel="nofollow noreferrer">https://www.freemaptools.com/download-uk-postcode-lat-lng.htm</a>
尤其是这个CSV文件(链接在同一页中):
<a href="https://www.freemaptools.com/download/full-postcodes/ukpostcodes.zip" rel="nofollow noreferrer">https://www.freemaptools.com/download/full-postcodes/ukpostcodes.zip</a></p>
<p>一旦你将地理坐标与你拥有的每个邮政编码相匹配(超出了这个问题的范围),假设你有一个表,其中有4列(即每个邮政编码有2个(lat,long)值)。
你可以用numpy计算距离。下面是一个例子:</p>
<pre><code>import numpy as np
latlong = np.random.random((3,4))
# Dummy table containing 3 records, will look like this:
# array([[ 0.258906 , 0.66073909, 0.25845113, 0.87433443],
# [ 0.7657047 , 0.48898144, 0.39812762, 0.66054291],
# [ 0.2839561 , 0.04679014, 0.40685189, 0.09550362]])
# The following will produce a numpy array with as many elements as your records
# (It's the Euclidean distance between the points)
distances = np.sqrt((latlong[:, 3] - latlong[:, 1])**2 + (latlong[:, 2] - latlong[:, 0])**2)
# and it look like this:
# array([ 0.21359582, 0.405643 , 0.13219825])
</code></pre>