mindspore.dataset.Dataset.filter

Dataset.filter(predicate, input_columns=None, num_parallel_workers=None)[source]

Filter dataset by prediction.

Parameters
  • predicate (callable) – Python callable which returns a boolean value. If False then filter the element.

  • input_columns (Union[str, list[str]], optional) – List of names of the input columns. If not provided or provided with None, the predicate will be applied on all columns in the dataset. Default: None.

  • num_parallel_workers (int, optional) – Number of workers to process the dataset in parallel. Default: None.

Returns

Dataset, dataset filtered.

Examples

>>> # generator data(0 ~ 63)
>>> # filter the data that greater than or equal to 11
>>> dataset = dataset.filter(predicate=lambda data: data < 11, input_columns = ["data"])