Christopher
Christopher

Reputation: 277

Multiplication of tensor with batch data and a matrix

Given a tensor A of shape [?, n, m] and a tensor W of shape [m, m], I want to multiply each tensor a of shape [n,m] of A with W resulting in a tensor of shape [?, n, m].

I thought I could somehow do this with reshaping W to shape [tf.shape(A)[0], n, m], but this does not result in a tensor of shape [?, n, m].

Upvotes: 1

Views: 99

Answers (1)

javidcf
javidcf

Reputation: 59681

Yes, you can indeed do that with reshaping:

tf.reshape(tf.matmul(tf.reshape(A, [-1, m]), W), [-1, n, m])

Upvotes: 1

Related Questions