Search code examples
numpytensorflowmatrix-multiplication

Reduce 3D tensor to 1D tensor in Tensorflow


Let's assume, I have a 3 dimensional tensor of shape [a, b, c]. I want to extract one dimension at model run time, e.g. [4, 2, c], so I would end up with with a 1 dimensional tensor [c].

The parameters of a and b are stored in different tensors of shape [a, 1] and [b, 1], so using tf.slice is not an option, as tf.slice only accepts a 1 dimensional scalar tensor.

Any ideas?

Thanks!


Solution

  • Probably you need to split the tensor with tf.split.

    https://www.tensorflow.org/api_docs/python/tf/split