import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;
with tf.variable_scope('V1'):
a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
with tf.variable_scope('V1', reuse=True):
a3 = tf.get_variable('a1')
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a1.name
print sess.run(a1)
print a3.name
print sess.run(a3)
输出:
V1/a1:0
[ 1.]
V1/a1:0
[ 1.]
分析:变量a1和a3一样的变量,名字和值都是一样的