# Getting the mode of a posterior

**URL:** <https://discourse.pymc.io/t/getting-the-mode-of-a-posterior/4008>\
**Category:** Questions\
**Created:** [October 23, 2019, 8:25am UTC](https://discourse.pymc.io/t/getting-the-mode-of-a-posterior/4008 "2019-10-23T08:25:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tboutelier](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tboutelier/32/1222_2.png) [@tboutelier](https://discourse.pymc.io/u/tboutelier)\
**Post date:** [October 23, 2019, 8:25am UTC](https://discourse.pymc.io/t/getting-the-mode-of-a-posterior/4008/1 "2019-10-23T08:25:55Z")

</div>

Hi,  
After getting the trace of my parameters with NUTS (for instance), how can I compute the mode of each of my parameters?  
Thanks!

---

<div class="post-metadata">

**Author:** ![clausherther](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/clausherther/32/414_2.png) [@clausherther](https://discourse.pymc.io/u/clausherther)\
**Post date:** [October 23, 2019, 1:20pm UTC](https://discourse.pymc.io/t/getting-the-mode-of-a-posterior/4008/2 "2019-10-23T13:20:48Z")

</div>

Since the values inside the trace are just 2-dimensional numpy arrays, you should be able to use  
`scipy.stats.mode` for this, similar to this:

> <https://stackoverflow.com/questions/16330831/most-efficient-way-to-find-mode-in-numpy-array>

I think the default of `axis=0` should work, but you may have to adjust this.  
So, something like this

```python
from scipy import stats

stats.mode(trace["my_var"], axis=0)

```

For medians, you can just use numpy:

```python
import numpy as np

np.median(trace["my_var"], axis=0)

```

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [October 23, 2019, 7:09pm UTC](https://discourse.pymc.io/t/getting-the-mode-of-a-posterior/4008/3 "2019-10-23T19:09:02Z")

</div>

To complement Claus’ answer, there are also [interesting functions in ArviZ](https://arviz-devs.github.io/arviz/) – see `az.summary` and `az.plot_posterior` in particular
