将秩列表 - R 张量堆叠成一个秩 - (R+1) RaggedTensor 。
用法
tf.ragged.stack(
values:typing.List[ragged_tensor.RaggedOrDense],
axis=0,
name=None
)参数
-
valuestf.Tensor或tf.RaggedTensor的列表。不得为空。所有values必须具有相同的等级和相同的dtype;但与tf.stack不同,它们可以具有任意尺寸大小。 -
axis一个 python 整数,指示堆叠的维度。 (注意:与tf.stack不同,axis参数必须是静态已知的。)仅当至少一个values值的等级是静态已知的时,才支持负值。 -
name返回张量的名称前缀(可选)。
返回
-
排名为
R+1的RaggedTensor(如果R>0)。如果R==0,则结果将作为一维Tensor返回,因为RaggedTensor只能在rank>1时使用。result.ragged_rank=1+max(axis, max(rt.ragged_rank for rt in values]))。
抛出
-
ValueError如果values为空,如果axis超出范围或输入张量具有不同的秩。
给定具有相同等级 R ( R >= axis ) 的张量或参差不齐的张量列表,返回一个等级 - R+1 RaggedTensor result 使得 result[i0...iaxis] 是 [value[i0...iaxis] for value in values] 。
例子:
# Stacking two ragged tensors.
t1 = tf.ragged.constant([[1, 2], [3, 4, 5]])
t2 = tf.ragged.constant([[6], [7, 8, 9]])
tf.ragged.stack([t1, t2], axis=0)
<tf.RaggedTensor [[[1, 2], [3, 4, 5]], [[6], [7, 8, 9]]]>
tf.ragged.stack([t1, t2], axis=1)
<tf.RaggedTensor [[[1, 2], [6]], [[3, 4, 5], [7, 8, 9]]]>
# Stacking two dense tensors with different sizes.
t3 = tf.constant([[1, 2, 3], [4, 5, 6]])
t4 = tf.constant([[5], [6], [7]])
tf.ragged.stack([t3, t4], axis=0)
<tf.RaggedTensor [[[1, 2, 3], [4, 5, 6]], [[5], [6], [7]]]>
相关用法
- Python tf.ragged.stack_dynamic_partitions用法及代码示例
- Python tf.ragged.segment_ids_to_row_splits用法及代码示例
- Python tf.ragged.cross用法及代码示例
- Python tf.ragged.boolean_mask用法及代码示例
- Python tf.ragged.map_flat_values用法及代码示例
- Python tf.ragged.range用法及代码示例
- Python tf.ragged.row_splits_to_segment_ids用法及代码示例
- Python tf.ragged.cross_hashed用法及代码示例
- Python tf.ragged.constant用法及代码示例
- 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.stack。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
