mindspore.dataset.Dataset.take

View Source On Gitee
Dataset.take(count=- 1)[source]

Take the first specified number of samples from the dataset.

Parameters

count (int, optional) – The desired number of samples to take. If the value exceeds the total number of samples in the dataset, all data will be returned. Default: -1 , will return all data.

Note

When there are operations that will change the number of samples of the dataset in the data pipeline, the location of the take operation can change its effect. For example, batch operation will combine the successive samples of the specified batch_size into 1 sample, so .batch(batch_size).take(1) will be equivalent to .take(batch_size).batch(batch_size).

Returns

Dataset, a new dataset with the above operation applied.

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)