# Broadcast dimensions across aesara/theano tensors

**URL:** <https://discourse.pymc.io/t/broadcast-dimensions-across-aesara-theano-tensors/11048>\
**Category:** version agnostic\
**Tags:** theano, aesara\
**Created:** [December 21, 2022, 7:46pm UTC](https://discourse.pymc.io/t/broadcast-dimensions-across-aesara-theano-tensors/11048 "2022-12-21T19:46:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarryS](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/harrys/32/5061_2.png) [@HarryS](https://discourse.pymc.io/u/HarryS)\
**Post date:** [December 21, 2022, 7:46pm UTC](https://discourse.pymc.io/t/broadcast-dimensions-across-aesara-theano-tensors/11048/1 "2022-12-21T19:46:26Z")

</div>

Hi,

I’d like to broadcast dimensions across aesara tensors.  
As an example, I can do this with numpy inputs as follows:

```auto
r, c = at.row(), at.col()
f_subtract = aesara.function([c,r], [r-c])

c_ = np.array([1,2]).reshape(2,1)
r_ = np.array([2,3,4]).reshape(1,3)

f_subtract(c_,r_)

```

which gives:

```auto
[array([[1., 2., 3.],
        [0., 1., 2.]])]

```

However, my inputs are tensors, not numpy arrays. When I use tensors as inputs I get the error:  
“Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?”.

Surely this is possible. My only other option is to loop through each tensor component and then stack the outputs.

Any pointers would be greatly helpful.  
Many thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [December 21, 2022, 8:16pm UTC](https://discourse.pymc.io/t/broadcast-dimensions-across-aesara-theano-tensors/11048/2 "2022-12-21T20:16:17Z")

</div>

You don’t need to ever compile an aesara function to do computation with symbolic tensors. Your code already contains the answer to your question: it’s just `r-c`.

---

<div class="post-metadata">

**Author:** ![HarryS](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/harrys/32/5061_2.png) [@HarryS](https://discourse.pymc.io/u/HarryS)\
**Post date:** [December 21, 2022, 9:19pm UTC](https://discourse.pymc.io/t/broadcast-dimensions-across-aesara-theano-tensors/11048/3 "2022-12-21T21:19:58Z")

</div>

AHH thanks!

I realised I hadn’t reshaped my tensors when working with them so it was giving my shape errors. You’re right, once I’ve reshaped them then everything works as expected!
