mindspore.dataset.Dataset.take

Dataset.take(count=- 1)[source]

Takes at most given numbers of elements from the dataset.

Note

  1. If count is greater than the number of elements in the dataset or equal to -1, all the elements in dataset will be taken.

  2. The order of using take and batch matters. If take is before batch operation, then take the given number of rows; otherwise take the given number of batches.

Parameters

count (int, optional) – Number of elements to be taken from the dataset. Default: -1 .

Returns

Dataset, dataset taken.

Examples

>>> import mindspore.dataset as ds
>>> mnist_dataset_dir = "/path/to/mnist_dataset_directory"
>>> dataset = ds.MnistDataset(dataset_dir=mnist_dataset_dir)
>>> # Take 50 samples from MNIST dataset.
>>> dataset = dataset.take(50)