# sklearn.metrics.pairwise.haversine_distances¶

sklearn.metrics.pairwise.haversine_distances(X, Y=None)[source]

Compute the Haversine distance between samples in X and Y

The Haversine (or great circle) distance is the angular distance between two points on the surface of a sphere. The first distance of each point is assumed to be the latitude, the second is the longitude, given in radians. The dimension of the data must be 2.

$D(x, y) = 2\arcsin[\sqrt{\sin^2((x1 - y1) / 2) + \cos(x1)\cos(y1)\sin^2((x2 - y2) / 2)}]$
Parameters
Xarray_like, shape (n_samples_1, 2)
Yarray_like, shape (n_samples_2, 2), optional
Returns
distance{array}, shape (n_samples_1, n_samples_2)

Notes

As the Earth is nearly spherical, the haversine formula provides a good approximation of the distance between two points of the Earth surface, with a less than 1% error on average.

Examples

We want to calculate the distance between the Ezeiza Airport (Buenos Aires, Argentina) and the Charles de Gaulle Airport (Paris, France)

>>> from sklearn.metrics.pairwise import haversine_distances