Update docstring for zeros_like:
- testable examples - clarify that input can be an array-like PiperOrigin-RevId: 288333496 Change-Id: I7b6bf1301a314dcb4fb505b386b82219236b43dd
This commit is contained in:
parent
9982d476dd
commit
7f304cc3ef
@ -2720,21 +2720,27 @@ def zeros_like(tensor, dtype=None, name=None, optimize=True):
|
||||
same type and shape as `tensor` with all elements set to zero. Optionally,
|
||||
you can use `dtype` to specify a new type for the returned tensor.
|
||||
|
||||
For example:
|
||||
Examples:
|
||||
|
||||
```python
|
||||
tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
|
||||
tf.zeros_like(tensor) # [[0, 0, 0], [0, 0, 0]]
|
||||
```
|
||||
>>> tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
|
||||
>>> tf.zeros_like(tensor)
|
||||
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
|
||||
array([[0, 0, 0],
|
||||
[0, 0, 0]], dtype=int32)>
|
||||
|
||||
>>> tf.zeros_like(tensor, dtype=tf.float32)
|
||||
<tf.Tensor: shape=(2, 3), dtype=float32, numpy=
|
||||
array([[0., 0., 0.],
|
||||
[0., 0., 0.]], dtype=float32)>
|
||||
|
||||
Args:
|
||||
tensor: A `Tensor`.
|
||||
dtype: A type for the returned `Tensor`. Must be `float16`, `float32`,
|
||||
`float64`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`,
|
||||
`complex64`, `complex128`, `bool` or `string`.
|
||||
`complex64`, `complex128`, `bool` or `string`. (optional)
|
||||
name: A name for the operation (optional).
|
||||
optimize: if true, attempt to statically determine the shape of 'tensor' and
|
||||
encode it as a constant.
|
||||
optimize: if `True`, attempt to statically determine the shape of `tensor`
|
||||
and encode it as a constant. (optional, defaults to `True`)
|
||||
|
||||
Returns:
|
||||
A `Tensor` with all elements set to zero.
|
||||
@ -2750,31 +2756,33 @@ def zeros_like_v2(
|
||||
name=None):
|
||||
"""Creates a tensor with all elements set to zero.
|
||||
|
||||
Given a single tensor (`tensor`), this operation returns a tensor of the
|
||||
same type and shape as `tensor` with all elements set to zero. Optionally,
|
||||
you can use `dtype` to specify a new type for the returned tensor.
|
||||
Given a single tensor or array-like object (`input`), this operation returns
|
||||
a tensor of the same type and shape as `input` with all elements set to zero.
|
||||
Optionally, you can use `dtype` to specify a new type for the returned tensor.
|
||||
|
||||
For example:
|
||||
Examples:
|
||||
|
||||
```python
|
||||
tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
|
||||
tf.zeros_like(tensor) # [[0, 0, 0], [0, 0, 0]] with dtype=int32
|
||||
>>> tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
|
||||
>>> tf.zeros_like(tensor)
|
||||
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
|
||||
array([[0, 0, 0],
|
||||
[0, 0, 0]], dtype=int32)>
|
||||
|
||||
If dtype of input `tensor` is `float32`, then the output is also of `float32`
|
||||
tensor = tf.constant([[1.0, 2.0, 3.0], [4, 5, 6]])
|
||||
tf.zeros_like(tensor) # [[0., 0., 0.], [0., 0., 0.]] with dtype=floa32
|
||||
>>> tf.zeros_like(tensor, dtype=tf.float32)
|
||||
<tf.Tensor: shape=(2, 3), dtype=float32, numpy=
|
||||
array([[0., 0., 0.],
|
||||
[0., 0., 0.]], dtype=float32)>
|
||||
|
||||
If you want to specify desired dtype of output `tensor`, then specify it in
|
||||
the op tensor = tf.constant([[1.0, 2.0, 3.0], [4, 5, 6]])
|
||||
tf.zeros_like(tensor,dtype=tf.int32) # [[0, 0, 0], [0, 0, 0]] with
|
||||
dtype=int32
|
||||
```
|
||||
>>> tf.zeros_like([[1, 2, 3], [4, 5, 6]])
|
||||
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
|
||||
array([[0, 0, 0],
|
||||
[0, 0, 0]], dtype=int32)>
|
||||
|
||||
Args:
|
||||
input: A `Tensor`.
|
||||
input: A `Tensor` or array-like object.
|
||||
dtype: A type for the returned `Tensor`. Must be `float16`, `float32`,
|
||||
`float64`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`,
|
||||
`complex64`, `complex128`, `bool` or `string`.
|
||||
`complex64`, `complex128`, `bool` or `string` (optional).
|
||||
name: A name for the operation (optional).
|
||||
|
||||
Returns:
|
||||
|
Loading…
Reference in New Issue
Block a user