Creates a tensor with all elements set to one. Given a single tensor (`tensor`), this operation returns a tensor of the same type and shape as `tensor` with all elements set to 1. Optionally, you can use `dtype` to specify a new type for the returned tensor. For example: ```python ten
(
input, # pylint: disable=redefined-builtin
dtype=None,
name=None)
| 2488 | @tf_export("ones_like", v1=[]) |
| 2489 | @dispatch.add_dispatch_support |
| 2490 | def ones_like_v2( |
| 2491 | input, # pylint: disable=redefined-builtin |
| 2492 | dtype=None, |
| 2493 | name=None): |
| 2494 | """Creates a tensor with all elements set to one. |
| 2495 | |
| 2496 | Given a single tensor (`tensor`), this operation returns a tensor of the |
| 2497 | same type and shape as `tensor` with all elements set to 1. Optionally, |
| 2498 | you can use `dtype` to specify a new type for the returned tensor. |
| 2499 | |
| 2500 | For example: |
| 2501 | |
| 2502 | ```python |
| 2503 | tensor = tf.constant([[1, 2, 3], [4, 5, 6]]) |
| 2504 | tf.ones_like(tensor) # [[1, 1, 1], [1, 1, 1]] |
| 2505 | ``` |
| 2506 | |
| 2507 | Args: |
| 2508 | input: A `Tensor`. |
| 2509 | dtype: A type for the returned `Tensor`. Must be `float16`, `float32`, |
| 2510 | `float64`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, |
| 2511 | `complex64`, `complex128`, `bool` or `string`. |
| 2512 | name: A name for the operation (optional). |
| 2513 | |
| 2514 | Returns: |
| 2515 | A `Tensor` with all elements set to one. |
| 2516 | """ |
| 2517 | return ones_like_impl(input, dtype, name, optimize=True) |
| 2518 | |
| 2519 | |
| 2520 | def ones_like_impl(tensor, dtype, name, optimize=True): |
nothing calls this directly
no test coverage detected