Well, do you want this in numpy or in Theano? In the case where, as you state, you want to compress the 3 A axis against the 2 axis of B, both are simple:
import numpy as np
a = np.arange(3 * 4 * 5).reshape(3, 4, 5).astype('float32')
b = np.arange(3 * 5).reshape(3, 5).astype('float32')
result = a.dot(b.T)
in Theano it is written as
import theano.tensor as T
A = T.ftensor3()
B = T.fmatrix()
out = A.dot(B.T)
out.eval({A: a, B: b})
(3, 4, 3). , (3, 4), numpy einsum, ,
einsum_out = np.einsum('ijk, ik -> ij', a, b)
Theano einsum. , :
out = (a * b[:, np.newaxis]).sum(2)
Theano
out = (A * B.dimshuffle(0, 'x', 1)).sum(2)
out.eval({A: a, B: b})