Returns the size of a potentially ragged tensor. The size of a ragged tensor is the size of its inner values. Args: input: A potentially ragged `Tensor`. out_type: The numeric output type for the operation. name: A name for the operation (optional). Returns: A Tensor of type
(input, out_type=dtypes.int32, name=None)
| 470 | |
| 471 | |
| 472 | def size(input, out_type=dtypes.int32, name=None): # pylint: disable=redefined-builtin |
| 473 | """Returns the size of a potentially ragged tensor. |
| 474 | |
| 475 | The size of a ragged tensor is the size of its inner values. |
| 476 | |
| 477 | Args: |
| 478 | input: A potentially ragged `Tensor`. |
| 479 | out_type: The numeric output type for the operation. |
| 480 | name: A name for the operation (optional). |
| 481 | |
| 482 | Returns: |
| 483 | A Tensor of type `out_type`. |
| 484 | |
| 485 | #### Example: |
| 486 | ```python |
| 487 | >>> tf.size(tf.ragged.constant([[1, 2], [3]])) |
| 488 | 3 |
| 489 | ``` |
| 490 | """ |
| 491 | if ragged_tensor.is_ragged(input): |
| 492 | return array_ops.size(input.flat_values, out_type=out_type, name=name) |
| 493 | else: |
| 494 | return array_ops.size(input, out_type=out_type, name=name) |
| 495 | |
| 496 | |
| 497 | #=============================================================================== |