Tozz
Tozz

Reputation: 276

How to deal with the product between matrix [None, 32, 32] and matrix [32, 32] with `tf.matmul`?

Before building a DNN model, I need to have the product of two matrixes: [None, 32, 32] and [32, 32]

Since I know that this method works (from the example of MNIST)

x = tf.placeholder("float", shape=[None, 784])
W = tf.Variable(tf.zeros([784,10]))
l = tf.matmul(x, W)

I try this one on my question

x = tf.placeholder(tf.float32, shape = [None, 64, 64])
w = t.Variable(tf.random_normal([64, 64], 0, 0.3))
l = tf.matmul(x, w)

But it is wrong.

-- I know that if w = t.Variable(tf.random_normal([constant, 64, 64], 0, 0.3)), this product could work. But I need the w to be the two-dimension matrix [64, 64].

Could I have one method that makes this product between [None, 32, 32] and [32, 32] successful?

Upvotes: 1

Views: 87

Answers (1)

Tozz
Tozz

Reputation: 276

This method solves my question

tf.einsum('ijk,kl->ijl', x, w)

And this is the wiki

Upvotes: 1

Related Questions