从嵌套的 Python 列表构造一个常量 RaggedTensor。
用法
tf.ragged.constant(
pylist, dtype=None, ragged_rank=None, inner_shape=None, name=None,
row_splits_dtype=tf.dtypes.int64
)参数
-
pylist嵌套的list,tuple或np.ndarray。任何不是list,tuple或np.ndarray的嵌套元素必须是与dtype兼容的标量值。 -
dtype返回的RaggedTensor的元素类型。如果未指定,则根据pylist中的标量值选择默认值。 -
ragged_rank一个整数,指定返回的RaggedTensor的不规则排名。必须为非负数且小于K。如果未指定inner_shape,则默认为max(0, K - 1)。如果指定了inner_shape,则默认为max(0, K - 1 - len(inner_shape))。 -
inner_shape一个整数元组,指定返回的RaggedTensor中各个内部值的形状。如果未指定ragged_rank,则默认为()。如果指定了ragged_rank,则根据pylist的内容选择默认值。 -
name返回张量的名称前缀(可选)。 -
row_splits_dtype构造的RaggedTensor的 row_splits 的数据类型。tf.int32或tf.int64之一。
返回
-
一个可能参差不齐的张量,秩为
K和指定的ragged_rank,包含来自pylist的值。
抛出
-
ValueError如果pylist中的标量值嵌套深度不一致;或者如果 ragged_rank 或 inner_shape 与pylist不兼容。
例子:
tf.ragged.constant([[1, 2], [3], [4, 5, 6]])
<tf.RaggedTensor [[1, 2], [3], [4, 5, 6]]>
pylist 中的所有标量值必须具有相同的嵌套深度 K ,并且返回的 RaggedTensor 将具有排名 K 。如果 pylist 不包含标量值,则 K 比 pylist 中空列表的最大深度大一。 pylist 中的所有标量值必须与 dtype 兼容。
相关用法
- Python tf.ragged.cross用法及代码示例
- Python tf.ragged.cross_hashed用法及代码示例
- Python tf.ragged.stack_dynamic_partitions用法及代码示例
- Python tf.ragged.boolean_mask用法及代码示例
- Python tf.ragged.stack用法及代码示例
- Python tf.ragged.map_flat_values用法及代码示例
- Python tf.ragged.range用法及代码示例
- Python tf.ragged.row_splits_to_segment_ids用法及代码示例
- Python tf.ragged.segment_ids_to_row_splits用法及代码示例
- Python tf.raw_ops.TPUReplicatedInput用法及代码示例
- Python tf.raw_ops.Bitcast用法及代码示例
- Python tf.raw_ops.SelfAdjointEigV2用法及代码示例
- Python tf.raw_ops.BatchMatMul用法及代码示例
- Python tf.raw_ops.OneHot用法及代码示例
- Python tf.raw_ops.ResourceScatterNdSub用法及代码示例
- Python tf.raw_ops.ReadVariableXlaSplitND用法及代码示例
- Python tf.raw_ops.GatherV2用法及代码示例
- Python tf.raw_ops.Expm1用法及代码示例
- Python tf.range用法及代码示例
- Python tf.raw_ops.BitwiseAnd用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.ragged.constant。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
