小编Luc*_*uca的帖子

二维数组的 Python Earth Mover 距离

我想计算两个二维阵列之间的地球移动距离(这些不是图像)。

现在我浏览了两个库:scipy ( https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wasserstein_distance.html ) 和pyemd ( https://pypi.org/project/pyemd / )。

#define a sampeling method
def sampeling2D(n, mu1, std1, mu2, std2):
   #sample from N(0, 1) in the 2D hyperspace
   x = np.random.randn(n, 2)

   #scale N(0, 1) -> N(mu, std)
   x[:,0] = (x[:,0]*std1) + mu1
   x[:,1] = (x[:,1]*std2) + mu2

   return x

#generate two sets
Y1 = sampeling2D(1000, 0, 1, 0, 1)
Y2 = sampeling2D(1000, -1, 1, -1, 1)

#compute the distance
distance = pyemd.emd_samples(Y1, Y2)
Run Code Online (Sandbox Code Playgroud)

虽然scipy …

python statistics distribution scipy earth-movers-distance

8
推荐指数
1
解决办法
3831
查看次数