# Vector hyperparameter for multivariate normal

**URL:** <https://discourse.pymc.io/t/vector-hyperparameter-for-multivariate-normal/14374>\
**Category:** v5\
**Created:** [May 2, 2024, 5:19am UTC](https://discourse.pymc.io/t/vector-hyperparameter-for-multivariate-normal/14374 "2024-05-02T05:19:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![donut](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@donut](https://discourse.pymc.io/u/donut)\
**Post date:** [May 2, 2024, 5:19am UTC](https://discourse.pymc.io/t/vector-hyperparameter-for-multivariate-normal/14374/1 "2024-05-02T05:19:52Z")

</div>

Hi, how can i make an multidimensional deterministic parameter. I want to have my mu end up being a 2d parameter for a bivariate gaussian likelihood. I still learning PYMC and have been searching through docs for answer. Any guidance or help is much appreciated

```auto
import arviz as az
import numpy as np
import pymc as pm

def q_mu(P,vi,n=1,m=1):
    q = np.dot(P,vi)
    return q

N = 100
# True parameter values
p_actual = np.array([[1,.25],[.255,1]])
v = np.array([1.4,1.4])
qmu_actual=q_mu(p_actual,v_actual)
sigma=np.array([[1.1,.4],[.4,1.2]])

# Size of dataset
size = 5

# Predictor variable
V1 = np.random.normal(1.4, .01, size)
V2 = np.random.normal(1.4, .01, size)

# Simulate outcome variable
x = rng.multivariate_normal(q_mu(p_actual,v),sigma, size=N)

coords = {"axis": ["x1", "x2"], "obs_id": np.arange(N)}
with pm.Model(coords=coords) as model:
    c11 = pm.Normal("c11", mu=1, sigma=10)
    c12 = pm.Normal("c12", mu=1*.255, sigma=10)
    c21 = pm.Normal("c21", mu=1*.255, sigma=10)
    c22 = pm.Normal("c22", mu=1, sigma=10)

with model:
    p = np.array([[c11, c12], [c21, c22]])
    v=np.array([1.4,1.4])
    mu=pm.math.dot(p,v)
    # mu=q_mu(p,v)
    # mu = pm.math.dot(p,v_actual)
    # mu = pm.Deterministic(name="mu",var=pm.math.dot(p,v),dims="axis")
    # mu = pm.Deterministic(name="mu",var=q_mu(p,v),dims="axis")
    obs = pm.MvNormal("obs", mu=mu, cov=sigma, observed=x, dims=("obs_id", "axis"))

```

I either get

```auto
TypeError: Unsupported dtype for TensorType

```

or

```auto
ValueError: order must be one of 'C', 'F', 'A', or 'K' (got 'mu')

```

Im sure its something dumb im doing, but I cant figure it out

---

<div class="post-metadata">

**Author:** ![iavicenna](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/iavicenna/32/7923_2.png) [@iavicenna](https://discourse.pymc.io/u/iavicenna)\
**Post date:** [May 3, 2024, 11:42am UTC](https://discourse.pymc.io/t/vector-hyperparameter-for-multivariate-normal/14374/2 "2024-05-03T11:42:29Z")

</div>

Hi,

You should use operations defined in pytensor.tensor to construct matrices of tensors. So the incorrect line is

```auto
p = np.array([[c11, c12], [c21, c22]])

```

Instead you can do

```auto
import pytensor.tensor as pt

p = pt.reshape(pt.stack([c11,c12,c21,c22]),(2,2))

```
