Returns the rank of a tensor. Returns a 0-D `int32` `Tensor` representing the rank of `input`. For example: ```python # shape of tensor 't' is [2, 2, 3] t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]) tf.rank(t) # 3 ``` **Note**: The rank of a tensor is not the
(input, name=None)
| 575 | @tf_export("rank") |
| 576 | @dispatch.add_dispatch_support |
| 577 | def rank(input, name=None): |
| 578 | # pylint: disable=redefined-builtin |
| 579 | """Returns the rank of a tensor. |
| 580 | |
| 581 | Returns a 0-D `int32` `Tensor` representing the rank of `input`. |
| 582 | |
| 583 | For example: |
| 584 | |
| 585 | ```python |
| 586 | # shape of tensor 't' is [2, 2, 3] |
| 587 | t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]) |
| 588 | tf.rank(t) # 3 |
| 589 | ``` |
| 590 | |
| 591 | **Note**: The rank of a tensor is not the same as the rank of a matrix. The |
| 592 | rank of a tensor is the number of indices required to uniquely select each |
| 593 | element of the tensor. Rank is also known as "order", "degree", or "ndims." |
| 594 | |
| 595 | Args: |
| 596 | input: A `Tensor` or `SparseTensor`. |
| 597 | name: A name for the operation (optional). |
| 598 | |
| 599 | Returns: |
| 600 | A `Tensor` of type `int32`. |
| 601 | |
| 602 | @compatibility(numpy) |
| 603 | Equivalent to np.ndim |
| 604 | @end_compatibility |
| 605 | """ |
| 606 | return rank_internal(input, name, optimize=True) |
| 607 | |
| 608 | |
| 609 | def rank_internal(input, name=None, optimize=True): |
no test coverage detected