1. 程式人生 > >tensorflow函式tf.scatter_sub()

tensorflow函式tf.scatter_sub()

tf.scatter_sub()作用是:

將ref中特定位置的數分別進行減法運算。

示例如下:

ref = tf.Variable([1, 2, 3, 4, 5, 6, 7, 8],dtype = tf.int32)
indices = tf.constant([4, 3, 1, 7],dtype = tf.int32)
updates = tf.constant([9, 10, 11, 12],dtype = tf.int32)
sub = tf.scatter_sub(ref, indices, updates)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print
sess.run(sub)

輸出:

[ 1 -9 3 -6 -4 6 7 -4]

(多維用tf.scatter_nd_sub)