我有张量' a',我想修改它的元素。
index = tf.where(a==2)
我可以获得该元素的索引。
b = tf.convert_to_tensor([[1.0, 1.0, 1.0],
[1.0, 0.0, 1.0],
[1.0, 1.0, 1.0]], dtype=tf.float32)
如何推导' b'来自' a'?
setBorder()
我知道我无法修改Date.prototype.isPrototypeOf
中的张量。
答案 0 :(得分:0)
我使用tf.sparse_to_dense()
解决了这个问题import tensorflow as tf
a = tf.convert_to_tensor([[1.0, 1.0, 1.0],
[1.0, 2.0, 1.0],
[1.0, 1.0, 1.0]], dtype=tf.float32)
index = tf.where(a > 1)
zero = tf.sparse_to_dense(index, tf.shape(a, out_type=tf.int64), 0., 1.)
update = tf.sparse_to_dense(index, tf.shape(a, out_type=tf.int64), 0., 0.)
b = a * zero + update
with tf.Session() as sess:
print sess.run(b)