user567879
user567879

Reputation: 5349

Element wise matrix multiplication in Theano

I could see element wise matrix multiplication using numpy can be done with * operator.

print np.mat(np.ones((10,10)))*np.mat(np.ones((10,10)))

But couldnt get it working under theano. The code I tried is

x = T.dmatrix('x')
y = T.dmatrix('y')
z = x * y
f1 = theano.function([x, y], z)

print f1(np.mat(np.ones((10,10))),np.mat(np.ones((10,10))))

Upvotes: 1

Views: 3388

Answers (1)

Roman
Roman

Reputation: 131228

If I try the following (which is basically your code):

import theano
import theano.tensor as T

import numpy as np

x = T.dmatrix('x')
y = T.dmatrix('y')
z = x * y
f1 = theano.function([x, y], z)

print f1(np.mat(np.ones((10,10))),np.mat(np.ones((10,10))))

I get the following:

[[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]]

So, it works for me.

Upvotes: 4

Related Questions