# Reshaping a numpy array in a pytensor compiled function

**URL:** <https://discourse.pymc.io/t/reshaping-a-numpy-array-in-a-pytensor-compiled-function/12321>\
**Category:** General\
**Created:** [June 15, 2023, 3:30pm UTC](https://discourse.pymc.io/t/reshaping-a-numpy-array-in-a-pytensor-compiled-function/12321 "2023-06-15T15:30:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![npschafer-cb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/npschafer-cb/32/6620_2.png) [@npschafer-cb](https://discourse.pymc.io/u/npschafer-cb)\
**Post date:** [June 15, 2023, 3:30pm UTC](https://discourse.pymc.io/t/reshaping-a-numpy-array-in-a-pytensor-compiled-function/12321/1 "2023-06-15T15:30:19Z")

</div>

If I use a series of operations like

```auto
array = pm.Normal( ... )
array_reshaped = array[:, np.newaxis]

```

and then go on to use `array_reshaped` later in the model, is that expected to cause problems for PyMC/PyTensor?

In other words, when the documentation for PyTensor says that it has tight integration with numpy, does that extend to these kinds of operations? Or do I have to use the PyTensor equivalent? And if so, what would it be?

Apologies if this isn’t clear, and thanks in advance for any guidance!

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 15, 2023, 4:38pm UTC](https://discourse.pymc.io/t/reshaping-a-numpy-array-in-a-pytensor-compiled-function/12321/2 "2023-06-15T16:38:34Z")

</div>

Yes you can do that. The same indexing operations are allowed in PyTensor variables as in numpy arrays.

To debug and check you are getting the expected shapes you can call `pm.draw(array_reshaped)` to get a random draw.

---

<div class="post-metadata">

**Author:** ![npschafer-cb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/npschafer-cb/32/6620_2.png) [@npschafer-cb](https://discourse.pymc.io/u/npschafer-cb)\
**Post date:** [June 15, 2023, 6:57pm UTC](https://discourse.pymc.io/t/reshaping-a-numpy-array-in-a-pytensor-compiled-function/12321/3 "2023-06-15T18:57:37Z")

</div>

Thank you, @ricardoV94!
