當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.RaggedTensor.to_sparse用法及代碼示例

用法

to_sparse(
    name=None
)

參數

  • name 返回張量的名稱前綴(可選)。

返回

  • self 具有相同值的 SparseTensor。

將此 RaggedTensor 轉換為 tf.sparse.SparseTensor

例子:

rt = tf.ragged.constant([[1, 2, 3], [4], [], [5, 6]])
print(rt.to_sparse())
SparseTensor(indices=tf.Tensor(
                 [[0 0] [0 1] [0 2] [1 0] [3 0] [3 1]],
                 shape=(6, 2), dtype=int64),
             values=tf.Tensor([1 2 3 4 5 6], shape=(6,), dtype=int32),
             dense_shape=tf.Tensor([4 3], shape=(2,), dtype=int64))

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.RaggedTensor.to_sparse。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。