# Wasserstein distance for histograms

**URL:** <https://discourse.julialang.org/t/wasserstein-distance-for-histograms/89083>\
**Category:** Statistics\
**Tags:** question\
**Created:** [October 21, 2022, 8:13pm UTC](https://discourse.julialang.org/t/wasserstein-distance-for-histograms/89083 "2022-10-21T20:13:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ignace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ignace/32/24275_2.png) [@ignace](https://discourse.julialang.org/u/ignace)\
**Post date:** [October 21, 2022, 8:13pm UTC](https://discourse.julialang.org/t/wasserstein-distance-for-histograms/89083/1 "2022-10-21T20:13:22Z")

</div>

Hello,  
How can one compute the Wasserstein distance between two histograms.  
To be clear, what I mean with a histogram is, e.g., the following `h` :  
`using StatsBase`  
`x = randn(10^4)`  
`h = fit(Histogram, x)`  
Looking forward to any suggestion.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 22, 2022, 8:54pm UTC](https://discourse.julialang.org/t/wasserstein-distance-for-histograms/89083/2 "2022-10-22T20:54:18Z")

</div>

> [@ignace](#):
>
> Looking forward to any suggestion

Including calling Python’s `wasserstein_distance()`?

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [October 22, 2022, 11:38pm UTC](https://discourse.julialang.org/t/wasserstein-distance-for-histograms/89083/3 "2022-10-22T23:38:53Z")

</div>

The trick was to get the right synonym for Wasserstein distance. In this case _earth mover distance_. A little google gives:

```julia
https://github.com/mirkobunse/EarthMoversDistance.jl

```

and following the instructions on the README I was able to calculate a distance.  
Thanks mirkobunse (Mirko Bunse).

Also, this thread might be relevant:

> [@Computing discrete Wasserstein (EMD) distance in Julia?](https://discourse.julialang.org/t/computing-discrete-wasserstein-emd-distance-in-julia/9600):
>
> Is there any library in Julia for computing discrete Wasserstein (EMD) given two discrete distributions? Python seems to have a tool for that [http://pot.readthedocs.io/en/stable/index.html](http://pot.readthedocs.io/en/stable/index.html), but if a pure Julia solution is available, it will be better than using PyCall.
