Convert einsum calculation to the point product to be used in Theano

I recently found out about np.einsumand quickly became addicted to it. But it theanodoesn't seem to have an equivalent function, so I need to somehow convert the code numpyto anano. How can I write the following calculation in anano?

IX=np.einsum('ijk,lj->ilk',p1,KX)
+4
source share
1 answer

You only need to change your axes to make this work:

>>> import numpy as np
>>> a = np.random.rand(3, 4, 5)
>>> b = np.random.rand(5, 6)
>>> np.allclose(np.einsum('ikj,jl->ikl', a, b), np.dot(a, b))

So, keeping in mind:

>>> a = np.random.rand(3, 5, 4)
>>> b = np.random.rand(6, 5)
>>> out_ein = np.einsum('ijk,lj->ilk', a, b)
>>> out_dot = np.transpose(np.dot(np.transpose(a, (0, 2, 1)),
...                               np.transpose(b, (1, 0))),
...                        (0, 2, 1))
>>> np.allclose(out_ein, out_dot)
+6
source

All Articles