返回包含指定數字序列的RaggedTensor。
用法
tf.ragged.range(
starts, limits=None, deltas=1, dtype=None, name=None,
row_splits_dtype=tf.dtypes.int64
)參數
-
starts向量或標量Tensor。如果limits不是None,則指定每個範圍的第一個條目;否則,指定範圍限製,第一個條目默認為0。 -
limits向量或標量Tensor。指定每個範圍的獨占上限。 -
deltas向量或標量Tensor。指定每個範圍的增量。默認為1。 -
dtype結果張量的元素類型。如果未指定,則根據其他參數選擇一個值。 -
name操作的名稱。 -
row_splits_dtypedtype用於返回的RaggedTensor的row_splits張量。tf.int32或tf.int64之一。
返回
-
RaggedTensor類型為dtype和ragged_rank=1。
返回的 RaggedTensor 的每一行都包含一個序列:
ragged.range(starts, limits, deltas)[i] ==
tf.range(starts[i], limits[i], deltas[i])
如果 start[i] < limits[i] and deltas[i] > 0 ,那麽 output[i] 將是一個空列表。同樣,如果 start[i] > limits[i] and deltas[i] < 0 ,那麽 output[i] 將是一個空列表。此行為與 Python range 函數一致,但與 tf.range 操作不同,後者在這些情況下返回錯誤。
例子:
tf.ragged.range([3, 5, 2]).to_list()
[[0, 1, 2], [0, 1, 2, 3, 4], [0, 1]]
tf.ragged.range([0, 5, 8], [3, 3, 12]).to_list()
[[0, 1, 2], [], [8, 9, 10, 11]]
tf.ragged.range([0, 5, 8], [3, 3, 12], 2).to_list()
[[0, 2], [], [8, 10]]
輸入張量 starts , limits 和 deltas 可以是標量或向量。向量輸入必須全部具有相同的大小。標量輸入被廣播以匹配向量輸入的大小。
相關用法
- Python tf.ragged.row_splits_to_segment_ids用法及代碼示例
- Python tf.ragged.cross用法及代碼示例
- Python tf.ragged.stack_dynamic_partitions用法及代碼示例
- Python tf.ragged.boolean_mask用法及代碼示例
- Python tf.ragged.stack用法及代碼示例
- Python tf.ragged.map_flat_values用法及代碼示例
- Python tf.ragged.cross_hashed用法及代碼示例
- Python tf.ragged.segment_ids_to_row_splits用法及代碼示例
- 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.range。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
