Reputation: 277
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
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