tf.sparse_retain
は動作するはずです:
import tensorflow as tf
a = tf.SparseTensor(indices=[[1, 2], [2, 2]], values=[0., 1.], shape=[3, 3])
with tf.Session() as session:
print(session.run([a, sparse_remove(a)]))
プリントが(私は少しそれを再フォーマットしました):
[SparseTensorValue(indices=array([[1, 2], [2, 2]]), values=array([ 0., 1.], dtype=float32), shape=array([3, 3])),
SparseTensorValue(indices=array([[2, 2]]), values=array([ 1.], dtype=float32), shape=array([3, 3]))]
例として
def sparse_remove(sparse_tensor, remove_value=0.):
return tf.sparse_retain(sparse_tensor, tf.not_equal(a.values, remove_value))