是。可以将张量转换为稀疏张量并返回:
设
sparse稀疏张量
dense为密集张量。
从稀疏到密集:
dense = tf.sparse_to_dense(sparse.indices, sparse.shape, sparse.values)
从密集到稀疏:
zero = tf.constant(0, dtype=tf.float32)where = tf.not_equal(dense, zero)indices = tf.where(where)values = tf.gather_nd(dense, indices)sparse = tf.SparseTensor(indices, values, dense.shape)



