在Python中,计算Earth Mover’s Distance (EMD)通常使用scipy
库中的scipy.stats.wasserstein_distance
函数,该函数计算的是Wasserstein距离,它与EMD非常相似,都是用来衡量两个分布之间的距离。
以下是一个简单的Python程序例子,展示了如何使用scipy.stats.wasserstein_distance
来计算两个一维分布之间的距离:
import numpy as np
from scipy.stats import wasserstein_distance
# 假设我们有两个一维分布,用numpy数组表示它们的概率质量函数
dist_a = np.array([0.1,