從嵌套的 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
