Search code examples
pythonnumpymatrixtheano

Theano matrix multiplication of 2d matrix to give 3d matrix


I want to do exactly what the following question is trying to do in numpy:
Numpy matrix multiplication of 2d matrix to give 3d matrix

I have written the following code (as per the suggestion for numpy case), assuming that broadcast works in theano as well:

y = T.dmatrix('y')
x = T.dmatrix('x')
z = x[...,None]*y[:,None,:]

But it is throwing following error:

AsTensorError: ('Cannot convert Ellipsis to TensorType', <type 'ellipsis'>)

Solution

  • As per @Divakar s comment, change it to

    x[:,:,None] * y[:,None,:]
    

    Just posting it as an answer so that people know there's an answer to this.