Shuffle Tensor Elements
In [34]:
import tensorflow as tfIn [35]:
startingArr = [
[10,13],
[21,31],
[1,9]
]
myTensor = tf.constant(startingArr)
myTensorOut [35]:
In [36]:
tf.random.shuffle(myTensor)Out [36]:
Shuffle With Seed
When a global seed is set, random will "always do the same thing", sort of "removing" 1 level of randomization.
Every time this notebook, or python process instance is run, the "random" outputs will remain constant.
In [37]:
tf.random.set_seed(12)
secondTensor = tf.constant(startingArr)
secondTensorOut [37]:
In [38]:
tf.random.shuffle(secondTensor)Out [38]:
In [39]:
tf.random.shuffle(secondTensor)Out [39]:
Shuffle With Global and local seed
A local seed, set in the tf.random.shuffle call as a parameter, will be combined with the global seed.
This local seed will "tell" tensorflow to create a "new" random order based on the local seed.
In [40]:
thirdTensor = tf.constant(startingArr)
thirdTensorOut [40]:
In [41]:
tf.random.shuffle(thirdTensor, seed=12)Out [41]:
In [42]:
tf.random.shuffle(thirdTensor, seed=13)Out [42]:
Docs
- tf.random.shuffle: randomly shuffles a tensor along its first dimension
- tf.random.set_seed: sets a global seed value