Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added examples to tf.clip_by_value #29774

Merged
merged 4 commits into from
Jun 25, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions tensorflow/python/ops/clip_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def clip_by_value(t, clip_value_min, clip_value_max,
Note: `clip_value_min` needs to be smaller or equal to `clip_value_max` for
correct results.

For example:

```python
A = tf.constant([[1, 20, 13], [3, 21, 13]])
B = tf.clip_by_value(A, clip_value_min=0, clip_value_max=3) # [[1, 3, 3],[3, 3, 3]]
C = tf.clip_by_value(A, clip_value_min=0., clip_value_max=3.) # throws `TypeError`
as input and clip_values are of different dtype
```

Args:
t: A `Tensor` or `IndexedSlices`.
clip_value_min: A 0-D (scalar) `Tensor`, or a `Tensor` with the same shape
Expand All @@ -62,6 +71,8 @@ def clip_by_value(t, clip_value_min, clip_value_max,
Raises:
ValueError: If the clip tensors would trigger array broadcasting
that would make the returned tensor larger than the input.
TypeError: If dtype of the input is `int32` and dtype of the `clip_value_min' or
`clip_value_max` is `float32`
"""
with ops.name_scope(name, "clip_by_value",
[t, clip_value_min, clip_value_max]) as name:
Expand Down