wasserstein distance python
时间: 2023-07-29 09:09:50 浏览: 136
The Wasserstein distance, also known as the Earth Mover's distance, is a measure of the dissimilarity between two probability distributions. In Python, you can compute the Wasserstein distance using the `scipy.stats` module. Here's an example:
```python
import numpy as np
from scipy.stats import wasserstein_distance
# Define two probability distributions
dist1 = np.array([0.2, 0.3, 0.5])
dist2 = np.array([0.1, 0.4, 0.5])
# Compute the Wasserstein distance
distance = wasserstein_distance(dist1, dist2)
print("Wasserstein distance:", distance)
```
In this example, `dist1` and `dist2` are two probability distributions represented as arrays. The `wasserstein_distance` function takes these arrays as input and returns the Wasserstein distance between them.
阅读全文