tf.random.experimental.stateless_shuffle  |  TensorFlow v2.16.1 (original) (raw)

tf.random.experimental.stateless_shuffle

Stay organized with collections Save and categorize content based on your preferences.

Randomly and deterministically shuffles a tensor along its first dimension.

View aliases

Compat aliases for migration

SeeMigration guide for more details.

tf.compat.v1.random.experimental.stateless_shuffle

tf.random.experimental.stateless_shuffle(
    value, seed, alg='auto_select', name=None
)

The tensor is shuffled along dimension 0, such that each value[j] is mapped to one and only one output[i]. For example, a mapping that might occur for a 3x2 tensor is:

[[1, 2],       [[5, 6],
 [3, 4],  ==>   [1, 2],
 [5, 6]]        [3, 4]]

v = tf.constant([[1, 2], [3, 4], [5, 6]]) shuffled = tf.random.experimental.stateless_shuffle(v, seed=[8, 9]) print(shuffled) tf.Tensor( [[5 6] [1 2] [3 4]], shape=(3, 2), dtype=int32)

This is a stateless version of tf.random.shuffle: if run twice with the same value and seed, it will produce the same result. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.

Args
value A Tensor to be shuffled.
seed A shape [2] Tensor. The seed to the random number generator. Must have dtype int32 or int64.
alg The RNG algorithm used to generate the random numbers. Seetf.random.stateless_uniform for a detailed explanation.
name A name for the operation.
Returns
A tensor of same shape and type as value, shuffled along its first dimension.