# Multidimensional Variables

**URL:** <https://discourse.pymc.io/t/multidimensional-variables/8813>\
**Category:** Questions\
**Tags:** theano\
**Created:** [February 16, 2022, 7:29am UTC](https://discourse.pymc.io/t/multidimensional-variables/8813 "2022-02-16T07:29:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueMan66](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/blueman66/32/2924_2.png) [@BlueMan66](https://discourse.pymc.io/u/BlueMan66)\
**Post date:** [February 16, 2022, 7:29am UTC](https://discourse.pymc.io/t/multidimensional-variables/8813/1 "2022-02-16T07:29:44Z")

</div>

Hi! I’m working in some Multinomial regression where the model is to be continuously updated with new observations.  
I’ve intended to use the `Interpolated` constructor to build priors for the multinomial probabilities from the previously sampled model. I came up with the following function to build my model:

```auto
def from_posterior(param:str, samples:np.ndarray, shape:tuple):

    smin, smax = np.min(samples), np.max(samples)
    width = smax - smin
    x = np.linspace(smin, smax, 100)
    y = stats.gaussian_kde(samples)(x)
    x = np.concatenate([[x[0] - 0.01 * width], x, [x[-1] + 0.1 * width]])
    y = np.concatenate([[0], y, [0]])
    return pm.Interpolated(param, x, y, shape = shape)

def model_from_posterior(number_of_outcomes:int, 
                         observed_data:pd.Series, 
                         prior_data:az.InferenceData)->pm.Model:

    total_observations = observed_data.sum()    
    with pm.Model() as model:
        probs = []
        for i, sample in enumerate(prior_data['probs'].T):
            probs.append(from_posterior(f'probs_{i}', sample, (1,)))

        probs = tt.as_tensor_variable(probs)
        likelihood = pm.Multinomial(
            'observed_values', n=total_observations, 
             p=probs,
             observed=observed_data)
    return model

```

My question is: How do I transform `probs` a multidimensional variable using theano for plotting purposes and are there any recommendations for plotting these kind of models?

---

<div class="post-metadata">

**Author:** ![ckrapu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ckrapu/32/1366_2.png) [@ckrapu](https://discourse.pymc.io/u/ckrapu)\
**Post date:** [February 17, 2022, 12:23pm UTC](https://discourse.pymc.io/t/multidimensional-variables/8813/2 "2022-02-17T12:23:46Z")

</div>

> How do I transform `probs` a multidimensional variable using theano for plotting purposes

We may need a little clarification to give you specific help here. If your main issue is that you would like to get the actual values of `probs` for plotting, you can use the `Deterministic` object to make sure that values of `probs` are stored in your trace. However, you could also get the same effect by just not overwriting the non-Theano typed variable `probs` by changing the line `probs = tt.as_tensor_variable(probs)` to use a different name.
