<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/ragged/ragged_factory_ops.py#L36-L93) |

Constructs a constant RaggedTensor from a nested Python list.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.ragged.constant`](https://www.tensorflow.org/api_docs/python/tf/ragged/constant)

<br />

    tf.ragged.constant(
        pylist,
        dtype=None,
        ragged_rank=None,
        inner_shape=None,
        name=None,
        row_splits_dtype=https://www.tensorflow.org/api_docs/python/tf/dtypes#int64
    ) -> Union[https://www.tensorflow.org/api_docs/python/tf/RaggedTensor, ops._EagerTensorBase, https://www.tensorflow.org/api_docs/python/tf/Operation]

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) - [Introduction to Tensors](https://www.tensorflow.org/guide/tensor) | - [TF Lattice Aggregate Function Models](https://www.tensorflow.org/lattice/tutorials/aggregate_function_models) - [TF.Text Metrics](https://www.tensorflow.org/text/tutorials/text_similarity) |

#### Example:

    tf.ragged.constant([[1, 2], [3], [4, 5, 6]])
    <tf.RaggedTensor [[1, 2], [3], [4, 5, 6]]>

All scalar values in `pylist` must have the same nesting depth `K`, and the
returned `RaggedTensor` will have rank `K`. If `pylist` contains no scalar
values, then `K` is one greater than the maximum depth of empty lists in
`pylist`. All scalar values in `pylist` must be compatible with `dtype`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `pylist` | A nested `list`, `tuple` or `np.ndarray`. Any nested element that is not a `list`, `tuple` or `np.ndarray` must be a scalar value compatible with `dtype`. |
| `dtype` | The type of elements for the returned `RaggedTensor`. If not specified, then a default is chosen based on the scalar values in `pylist`. If there are no scalar values in `pylist`, then the default is [`tf.float32`](https://www.tensorflow.org/api_docs/python/tf#float32). |
| `ragged_rank` | An integer specifying the ragged rank of the returned `RaggedTensor`. Must be nonnegative and less than `K`. Defaults to `max(0, K - 1)` if `inner_shape` is not specified. Defaults to \`max(0, K <br /> - 1 - len(inner_shape))`if`inner_shape`is specified. </td> </tr><tr> <td>`inner_shape`<a id="inner_shape"></a> </td> <td> A tuple of integers specifying the shape for individual inner values in the returned`RaggedTensor`. Defaults to`()`if`ragged_rank`is not specified. If`ragged_rank`is specified, then a default is chosen based on the contents of`pylist`. </td> </tr><tr> <td>`name`<a id="name"></a> </td> <td> A name prefix for the returned tensor (optional). </td> </tr><tr> <td>`row_splits_dtype`<a id="row_splits_dtype"></a> </td> <td> data type for the constructed`RaggedTensor\`'s row_splits. One of [`tf.int32`](https://www.tensorflow.org/api_docs/python/tf#int32) or [`tf.int64`](https://www.tensorflow.org/api_docs/python/tf#int64). |

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A potentially ragged tensor with rank `K` and the specified `ragged_rank`, containing the values from `pylist`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the scalar values in `pylist` have inconsistent nesting depth; or if ragged_rank or inner_shape are incompatible with `pylist`. |

<br />