本文共 1130 字,大约阅读时间需要 3 分钟。
scatter_nd_sub
Example 1: subtraction at the second dimension, [0,1], which corresponding to a vector.
>>> ref = tf.Variable(tf.ones([2,3,3],tf.int32)) >>> indices = tf.constant([[0,1]])>>> updates = tf.constant([[1,1,1]]) >>> init = tf.global_variables_initializer()>>> sess.run(init)>>> print(ref.eval())[[[1 1 1] [1 1 1] [1 1 1]] [[1 1 1] [1 1 1] [1 1 1]]]>>> print(updates.eval())[[1 1 1]]>>> update = tf.scatter_nd_sub(ref,indices,updates)>>> sess.run(update)array([[[1, 1, 1], [0, 0, 0], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1, 1, 1]]], dtype=int32)
Example 2: subtraction at the third dimension, [0,1,2], which points to a single element.
>>> ref = tf.Variable(tf.ones([2,3,3],tf.int32))>>> indices = tf.constant([[0,1,2]])>>> updates = tf.constant([1])>>> init = tf.global_variables_initializer()>>> sess.run(init)>>> print(ref.eval())[[[1 1 1] [1 1 1] [1 1 1]] [[1 1 1] [1 1 1] [1 1 1]]]>>> print(updates.eval())[1]>>> update = tf.scatter_nd_sub(ref,indices,updates)>>> sess.run(update)array([[[1, 1, 1], [1, 1, 0], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1, 1, 1]]], dtype=int32)
转载地址:http://loqbi.baihongyu.com/