Add example code to tf.data.Dataset.filter() documentation

This commit is contained in:
Karl Weinmeister 2019-02-01 16:11:47 -06:00 committed by GitHub
parent fdef225933
commit 5679c6f03a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1100,6 +1100,21 @@ class DatasetV2(object):
def filter(self, predicate):
"""Filters this dataset according to `predicate`.
```python
# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { 1, 2, 3 }
b = { 4, 5, 6, 7 }
a.filter(lambda x: x < 3) == { 1, 2 }
# `tf.math.equal(x, y)` is required for equality comparison
def filter_fn(x):
return tf.math.equal(x, 4)
b.filter(filter_fn) == { 4 }
```
Args:
predicate: A function mapping a nested structure of tensors (having shapes
and types defined by `self.output_shapes` and `self.output_types`) to a