Created
October 30, 2024 13:51
-
-
Save pmeier/a61e5cbfff3e67130d01194068288534 to your computer and use it in GitHub Desktop.
Haversine distance matrix numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def haversine_distance_matrix(lats, longs): | |
lats = np.radians(lats.reshape(-1, 1)) | |
longs = np.radians(longs.reshape(1, -1)) | |
return 2 * np.arcsin(np.sqrt((1 - np.cos(lats - lats.T) + np.cos(lats) * np.cos(lats.T) * (1 - np.cos(longs - longs.T))) / 2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment