# Mixture of vector valued random variables

**URL:** <https://discourse.pymc.io/t/mixture-of-vector-valued-random-variables/2007>\
**Category:** Questions\
**Created:** [October 4, 2018, 2:30pm UTC](https://discourse.pymc.io/t/mixture-of-vector-valued-random-variables/2007 "2018-10-04T14:30:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatG](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@MatG](https://discourse.pymc.io/u/MatG)\
**Post date:** [October 4, 2018, 2:30pm UTC](https://discourse.pymc.io/t/mixture-of-vector-valued-random-variables/2007/1 "2018-10-04T14:30:21Z")

</div>

In my data set there are D number of observations. Each observation is an N dimensional binary vector.  
I want to represent this data as a K mixture of N-D Binomial distributions.

```auto
model = pm.Model()
K = 4
N = 8
with model:

    w = pm.Dirichlet('w', a = np.ones(K), shape = K)

    p_ = pm.Dirichlet('p_', a = np.ones((K, N)), shape = (K, N))

    components = []
    for k in range(K):
        components.append(pm.Bernoulli.dist(p = p_[k]))
    like = pm.Mixture('like', w=w, comp_dists = components, observed = data)

```

I get the following error.  
`ValueError: Input dimension mis-match. (input[0].shape[2] = 4, input[1].shape[2] = 8)`

How can I fix this?  
Also any way I could avoid the for loop please?  
thanks

---

<div class="post-metadata">

**Author:** ![ded](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@ded](https://discourse.pymc.io/u/ded)\
**Post date:** [October 4, 2018, 9:21pm UTC](https://discourse.pymc.io/t/mixture-of-vector-valued-random-variables/2007/2 "2018-10-04T21:21:59Z")

</div>

I think your data should be of shape (N, K).  
your component can be set with:  
components = pm.Bernoulli.dist(p = p\_, shape = (K, N))

---

<div class="post-metadata">

**Author:** ![MatG](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@MatG](https://discourse.pymc.io/u/MatG)\
**Post date:** [October 9, 2018, 3:03pm UTC](https://discourse.pymc.io/t/mixture-of-vector-valued-random-variables/2007/3 "2018-10-09T15:03:53Z")

</div>

There are D number of observations, each observation is N dimensional binary vector. So my data is a D \times N matrix.
