# Dynamic number of Dirichlet distributions?

**URL:** <https://discourse.pymc.io/t/dynamic-number-of-dirichlet-distributions/881>\
**Category:** Questions\
**Created:** [February 22, 2018, 10:39pm UTC](https://discourse.pymc.io/t/dynamic-number-of-dirichlet-distributions/881 "2018-02-22T22:39:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![colcarroll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/colcarroll/32/9_2.png) [@colcarroll](https://discourse.pymc.io/u/colcarroll)\
**Post date:** [February 22, 2018, 10:39pm UTC](https://discourse.pymc.io/t/dynamic-number-of-dirichlet-distributions/881/1 "2018-02-22T22:39:46Z")

</div>

I am trying to define a model that looks like

```auto
nvars, ncats = 3, 5

with pm.Model():
    α = pm.Exponential('α', lam=λ, shape=(nvars, ncats))
    b = pm.Dirichlet('b', a=α)
    trace = pm.sample()

```

This fails, because the Dirichlet distribution expects an array, not a matrix, in `PyMC3` (and in `numpy`, and in `scipy`).

Has anyone had any success in modelling something like this? I guess I can use loops…

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [February 22, 2018, 10:57pm UTC](https://discourse.pymc.io/t/dynamic-number-of-dirichlet-distributions/881/2 "2018-02-22T22:57:27Z")

</div>

It should work, have you try specifying the shape of `b`?

---

<div class="post-metadata">

**Author:** ![colcarroll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/colcarroll/32/9_2.png) [@colcarroll](https://discourse.pymc.io/u/colcarroll)\
**Post date:** [February 25, 2018, 12:35pm UTC](https://discourse.pymc.io/t/dynamic-number-of-dirichlet-distributions/881/3 "2018-02-25T12:35:40Z")

</div>

I could have sworn I tried that… works fine once the shape is specified!

Once [the shape pull request](https://github.com/pymc-devs/pymc3/pull/1125) is settled, I might try to make sure that is detected automatically…

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [February 25, 2018, 12:44pm UTC](https://discourse.pymc.io/t/dynamic-number-of-dirichlet-distributions/881/4 "2018-02-25T12:44:49Z")

</div>

Shape issue is one of our daily struggle 😂
