0

I have a tensor list and each element has different shapes. For example, there are two tensors in my list, the shape of the first one is 333 and the second one is 4*4. I want to randomly sample a tensor from them in TensorFlow. But I don't know how to do it.

My approach now to reshape all the tensors to 1*N and use tf.concat to create a new tensor. Then I can use tf.gather. But this is to slow. I want to choose the tensor by using the index directly.

  • 1
    What are the sizes of the tensors, if it's a list of tensor you can easily sample randomly from it regardless of what type is contained in the list using `random.choice()` – David Sep 07 '20 at 05:41
  • Does this answer your question? [How to randomly select an item from a list?](https://stackoverflow.com/questions/306400/how-to-randomly-select-an-item-from-a-list) – tornikeo Sep 07 '20 at 06:42

0 Answers0