Reputation: 55
Say I have a tensor with shape (?, 5, 1, 20)
For each occurence of the last dimension I do some computation (getting the k max values) on the last dimension that produces a smaller tensor b. What do I do if want to replace the last dimension of my original tensor with b?
What (preferably pure tensorflow) path should I take?
Upvotes: 0
Views: 1652
Reputation: 2474
You're doing some computation on last dimension...That is you want to go from (?, 5, 1, 20) -> (?, 5, 1, b) if I understood correctly?
What kind of computation?
You could reshape your tensor, do the computation (such as matrix multiplication) and reshape back.
a = tf.reshape(X, [-1, 20])
a = tf.matmul(a, X)
a = tf.reshape(a, [-1, b])
Or you could use tf.einsum()
to achieve similar feat. For non-linear computation depends what you want to do.
EDIT: Also you could hack it with Conv2D and using filter of size [1,1, 20, b]. Does the same thing and more efficiently
Upvotes: 2