st = ... # A `tf.SparseTensor` object.
# Compute a vector of booleans indicating which values of `st` should be dropped
# (if False) or retained (if True)
is_nonzero = tf.not_equal(st.values, 0)
# `tf.sparse_retain()` computes a new `tf.SparseTensor` with the specified values
# retained in the output.
st_without_zeros = tf.sparse_retain(st, is_nonzero)
您可以使用^{} 操作解决此问题:
相关问题 更多 >
编程相关推荐