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.
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. See
tf.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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.random.experimental.stateless_shuffle\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/stateless_random_ops.py#L226-L271) |\n\nRandomly and deterministically shuffles a tensor along its first dimension.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.random.experimental.stateless_shuffle`](https://www.tensorflow.org/api_docs/python/tf/random/experimental/stateless_shuffle)\n\n\u003cbr /\u003e\n\n tf.random.experimental.stateless_shuffle(\n value, seed, alg='auto_select', name=None\n )\n\nThe tensor is shuffled along dimension 0, such that each `value[j]` is mapped\nto one and only one `output[i]`. For example, a mapping that might occur for a\n3x2 tensor is: \n\n [[1, 2], [[5, 6],\n [3, 4], ==\u003e [1, 2],\n [5, 6]] [3, 4]]\n\n v = tf.constant([[1, 2], [3, 4], [5, 6]])\n shuffled = tf.random.experimental.stateless_shuffle(v, seed=[8, 9])\n print(shuffled)\n tf.Tensor(\n [[5 6]\n [1 2]\n [3 4]], shape=(3, 2), dtype=int32)\n\nThis is a stateless version of [`tf.random.shuffle`](../../../tf/random/shuffle): if run twice with the\nsame `value` and `seed`, it will produce the same result. The\noutput is consistent across multiple runs on the same hardware (and between\nCPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU\nhardware.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `value` | A Tensor to be shuffled. |\n| `seed` | A shape \\[2\\] Tensor. The seed to the random number generator. Must have dtype `int32` or `int64`. |\n| `alg` | The RNG algorithm used to generate the random numbers. See [`tf.random.stateless_uniform`](../../../tf/random/stateless_uniform) for a detailed explanation. |\n| `name` | A name for the operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor of same shape and type as `value`, shuffled along its first dimension. ||\n\n\u003cbr /\u003e"]]