用法
merge_dims(
outer_axis, inner_axis
)
參數
-
outer_axis
int
:要合並的維度範圍中的第一個維度。如果self.shape.rank
是靜態已知的,則可能為負數。 -
inner_axis
int
:要合並的維度範圍中的最後一個維度。如果self.shape.rank
是靜態已知的,則可能為負數。
返回
-
此張量的副本,指定的維度合並為一個維度。返回張量的形狀將為
self.shape[:outer_axis] + [N] + self.shape[inner_axis + 1:]
,其中N
是合並維度中的切片總數。
將 outer_axis...inner_axis 合並到一個維度中。
返回此 RaggedTensor 的副本,其中指定的維度範圍被展平為單個維度,其中元素按行優先順序排列。
例子:
rt = tf.ragged.constant([[[1, 2], [3]], [[4, 5, 6]]])
print(rt.merge_dims(0, 1))
<tf.RaggedTensor [[1, 2], [3], [4, 5, 6]]>
print(rt.merge_dims(1, 2))
<tf.RaggedTensor [[1, 2, 3], [4, 5, 6]]>
print(rt.merge_dims(0, 2))
tf.Tensor([1 2 3 4 5 6], shape=(6,), dtype=int32)
要模仿 np.flatten
的行為(將所有維度展平),請使用 rt.merge_dims(0, -1). To mimic the behavior of
tf.layers.Flatten (which
flattens all dimensions except the outermost batch dimension), use
rt.merge_dims(1, -1)`。
相關用法
- Python tf.RaggedTensor.row_lengths用法及代碼示例
- Python tf.RaggedTensor.__rmul__用法及代碼示例
- Python tf.RaggedTensor.from_uniform_row_length用法及代碼示例
- Python tf.RaggedTensor.__radd__用法及代碼示例
- Python tf.RaggedTensor.__pow__用法及代碼示例
- Python tf.RaggedTensor.__rand__用法及代碼示例
- Python tf.RaggedTensor.numpy用法及代碼示例
- Python tf.RaggedTensor.get_shape用法及代碼示例
- Python tf.RaggedTensor.__xor__用法及代碼示例
- Python tf.RaggedTensor.__gt__用法及代碼示例
- Python tf.RaggedTensor.__getitem__用法及代碼示例
- Python tf.RaggedTensor.__rpow__用法及代碼示例
- Python tf.RaggedTensor.row_limits用法及代碼示例
- Python tf.RaggedTensor.nested_value_rowids用法及代碼示例
- Python tf.RaggedTensor.__rxor__用法及代碼示例
- Python tf.RaggedTensor.from_value_rowids用法及代碼示例
- Python tf.RaggedTensor.from_nested_row_lengths用法及代碼示例
- Python tf.RaggedTensor.__ror__用法及代碼示例
- Python tf.RaggedTensor.__rsub__用法及代碼示例
- Python tf.RaggedTensor.__abs__用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.RaggedTensor.merge_dims。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。