Returns the number of rows in this ragged tensor. I.e., the size of the outermost dimension of the tensor. Args: out_type: `dtype` for the returned tensor. Defaults to `self.row_splits.dtype`. name: A name prefix for the returned tensor (optional). Returns:
(self, out_type=None, name=None)
| 1023 | return tuple(rt_nested_ids) |
| 1024 | |
| 1025 | def nrows(self, out_type=None, name=None): |
| 1026 | """Returns the number of rows in this ragged tensor. |
| 1027 | |
| 1028 | I.e., the size of the outermost dimension of the tensor. |
| 1029 | |
| 1030 | Args: |
| 1031 | out_type: `dtype` for the returned tensor. Defaults to |
| 1032 | `self.row_splits.dtype`. |
| 1033 | name: A name prefix for the returned tensor (optional). |
| 1034 | |
| 1035 | Returns: |
| 1036 | A scalar `Tensor` with dtype `out_type`. |
| 1037 | |
| 1038 | #### Example: |
| 1039 | ```python |
| 1040 | >>> rt = ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []]) |
| 1041 | >>> rt.nrows() # rt has 5 rows. |
| 1042 | 5 |
| 1043 | ``` |
| 1044 | """ |
| 1045 | if out_type is None: |
| 1046 | out_type = self._row_splits.dtype |
| 1047 | else: |
| 1048 | out_type = dtypes.as_dtype(out_type) |
| 1049 | if self._cached_nrows is not None: |
| 1050 | return math_ops.cast(self._cached_nrows, out_type) |
| 1051 | with ops.name_scope(name, "RaggedNRows", [self]): |
| 1052 | return array_ops.shape(self.row_splits, out_type=out_type)[0] - 1 |
| 1053 | |
| 1054 | def row_starts(self, name=None): |
| 1055 | """Returns the start indices for rows in this ragged tensor. |