tf.assign_add(ref,value,use_lockingNone,nameNone)
Update ref by adding value to it.
This operation outputs “ref” after the update is done. This makes it easier to chain operations that need to use the reset value.
Args: ref: A mutable Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half. Should be from a Variable node. value: A Tensor. Must have the same type as ref. The value to be added to the variable. use_locking: An optional bool. Defaults to False. If True, the addition will be protected by a lock; otherwise the behavior is undefined, but may exhibit less contention. name: A name for the operation (optional).
b tf.ones([3,3],dtypetf.float32)c tf.Variable(tf.random_normal([3,3],mean1,stddev2,dtypetf.float32),name"c")d tf.assign_add(c,b)init_op tf.global_variables_initializer()with tf.Session() as sess:sess.run(init_op)x, y , z sess.run([c,b,d])print(x," \n!!!\n",y, "\n!!!\n", z, "\n!!!")print(sess.run(d))
输出
[[ 4.723362 0.44867647 0.27219188][ 5.9517117 1.8866203 3.3032823 ][-2.2057695 1.8035562 -0.53330874]] !!![[1. 1. 1.][1. 1. 1.][1. 1. 1.]] !!![[ 4.723362 0.44867647 0.27219188][ 5.9517117 1.8866203 3.3032823 ][-2.2057695 1.8035562 -0.53330874]] !!![[ 5.723362 1.4486765 1.2721919 ][ 6.9517117 2.8866203 4.3032823 ][-1.2057695 2.8035562 0.46669126]]
突然发现用x, y , z sess.run([c,b,d])跑的话c和d结果一样。。。