Search code examples
pythontensorflowtheano

How to multipy two 4D TensorVariable, python


I have two 4D TensorVariable, X=[100,1,28,28] and W=[100,1,28,28]. The X is including 100 images (one-channel) with the size of (28,28). The W is its corresponding weights for the 100 images. We want to multiply each image to its weights. In another word, I want 100 image in which each individual image comes from T.dot(a,b) where a is one image and b is its weight.

T.dot(X,W) is not working for me because it gives me a 5D TensorVariable.


Solution

  • The Theano T.dot function is a matrix multiplication (inner product). You want an element-wise multiplication, which, as described in the documentation, is simply done using the * operator, i.e.

    X * W