Skip to content Skip to sidebar Skip to footer

Tensorflow Tf.gather With Axis Parameter

I am using tensorflow's tf.gather to get elements from a multidimensional array like this: import tensorflow as tf indices = tf.constant([0, 1, 1]) x = tf.constant([[1, 2, 3],

Solution 1:

You need to convert the indices to full indices, and using gather_nd. Can be achieved by doing:

result = tf.squeeze(tf.gather_nd(x,tf.stack([tf.range(indices.shape[0])[...,tf.newaxis], indices[...,tf.newaxis]], axis=2)))

Post a Comment for "Tensorflow Tf.gather With Axis Parameter"