# Function Differences with tf.data.Dataset.shuffle ## tf.data.Dataset.shuffle ```python tf.data.Dataset.shuffle( buffer_size, seed=None, reshuffle_each_iteration=None ) ``` For more information, see [tf.data.Dataset.shuffle](https://www.tensorflow.org/versions/r2.6/api_docs/python/tf/data/Dataset#shuffle). ## mindspore.dataset.GeneratorDataset.shuffle ```python mindspore.dataset.GeneratorDataset.shuffle( buffer_size ) ``` For more information, see [mindspore.dataset.GeneratorDataset.shuffle](https://www.mindspore.cn/docs/en/r2.0.0-alpha/api_python/dataset/dataset_method/operation/mindspore.dataset.Dataset.shuffle.html#mindspore.dataset.Dataset.shuffle). ## Differences TensorFlow: Randomly shuffle the data in the pipeline. It supports setting a random seed and whether to reshuffle at each iteration. MindSpore: Randomly shuffle the data in the pipeline. The global random seed can be set through `mindspore.dataset.config.set_seed`, and it will reshuffe every iteration. ## Code Example ```python # The following implements shuffle with MindSpore. import numpy as np import mindspore.dataset as ds ds.config.set_seed(57) data = np.array([[1, 2], [3, 4], [5, 6]]) dataset = ds.NumpySlicesDataset(data=data, column_names=["data"], shuffle=False) dataset = dataset.shuffle(2) for item in dataset.create_dict_iterator(): print(item["data"]) # [1 2] # [5 6] # [3 4] # The following implements shuffle with TensorFlow. import tensorflow as tf tf.compat.v1.enable_eager_execution() data = tf.constant([[1, 2], [3, 4], [5, 6]]) dataset = tf.data.Dataset.from_tensor_slices(data) dataset = dataset.shuffle(2, seed=57) for value in dataset.take(3): print(value) # [3 4] # [5 6] # [1 2] ```