将值分配给在Tensorflow中从SparseTensor转换的DenseTensor

时间:2018-02-09 11:18:05

标签: python-3.x tensorflow

我有一个测试代码可以最低限度地解释我的问题:

import tensorflow as tf

t = tf.Variable([[1], [0], [2], [0]], tf.int32)
print(t)
tf.assign(t, [[0], [0], [0], [0]]) # this will succeed

t1 = tf.SparseTensor(indices=[[0, 0], [2, 0]], values=["1", "2"],         dense_shape=[4, 1])
t2 = tf.sparse_tensor_to_dense(t1, default_value="0")
t3 = tf.string_to_number(t2, out_type=tf.int32)
print(t3)
tf.assign(t3, [[0], [0], [0], [0]]) # this will fail with     "AttributeError: 'Tensor' object has no attribute 'assign'"

我想知道是因为Tensor的可变性还是其他原因?

我可以用dtype = tf.string直接更改SparseTensor中的值吗?

0 个答案:

没有答案