mindspore.dataset.Dataset.apply

Dataset.apply(apply_func)[source]

Apply a function in this dataset.

Parameters

apply_func (function) – A function that must take one Dataset as an argument and return a preprocessed Dataset .

Returns

Dataset, a new dataset with the above operation applied.

Examples

>>> import mindspore.dataset as ds
>>> dataset = ds.GeneratorDataset([i for i in range(10)], "column1")
>>>
>>> # Declare an apply_func function which returns a Dataset object
>>> def apply_func(data):
...     data = data.batch(2)
...     return data
>>>
>>> # Use apply to call apply_func
>>> dataset = dataset.apply(apply_func)
Raises
  • TypeError – If apply_func is not a function.

  • TypeError – If apply_func doesn't return a Dataset.