Skip to content Skip to sidebar Skip to footer

Tensorflow: How To Select Random Values From Tensor While Excluding Padded Values?

I have a batch of Tensorflow tensors which are batched by dataset.padded_batch since the tensors vary in length. From these Tensors, I would like to select several random values,

Solution 1:

Try x[x>-1]:

y1 = tf.py_func(lambda x, s: np.random.choice(x[x>-1].reshape(-1),s), [data[0], size], tf.int64)
y2 = tf.py_func(lambda x, s: np.random.choice(x[x>-1].reshape(-1),s), [data[1], size], tf.int64)
y3 = tf.py_func(lambda x, s: np.random.choice(x[x>-1].reshape(-1),s), [data[2], size], tf.int64)

Post a Comment for "Tensorflow: How To Select Random Values From Tensor While Excluding Padded Values?"