tf.ragged.constant_value(
pylist,
dtype=None,
ragged_rank=None,
inner_shape=None
)
Defined in tensorflow/python/ops/ragged/ragged_factory_ops.py.
Constructs a RaggedTensorValue from a nested Python list.
Example:
>>> ragged.constant_value([[1, 2], [3], [4, 5, 6]])
RaggedTensorValue(values=[1, 2, 3, 4, 5, 6], splits=[0, 2, 3, 6])
All scalar values in pylist must have the same nesting depth K, and the
returned RaggedTensorValue 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.
Args:
pylist: A nestedlistortuple. Any nested element that is not alistortuplemust be a scalar value compatible withdtype.dtype:numpy.dtype. The type of elements for the returnedRaggedTensor. If not specified, then a default is chosen based on the scalar values inpylist.ragged_rank: An integer specifying the ragged rank of the returnedRaggedTensorValue. Must be nonnegative and less thanK. Defaults tomax(0, K - 1)ifinner_shapeis not specified. Defaults to `max(0, K- 1 - len(inner_shape))
ifinner_shape` is specified.
- 1 - len(inner_shape))
inner_shape: A tuple of integers specifying the shape for individual inner values in the returnedRaggedTensorValue. Defaults to()ifragged_rankis not specified. Ifragged_rankis specified, then a default is chosen based on the contents ofpylist.
Returns:
A RaggedTensorValue or numpy.array with rank K and the specified
ragged_rank, containing the values from pylist.
Raises:
ValueError: If the scalar values inpylisthave inconsistent nesting depth; or if ragged_rank or inner_shape are incompatible withpylist.