# tf.variable_scope和tf.name_scope的用法

tf.variable_scope可以让变量有相同的命名，包括tf.get_variable得到的变量，还有tf.Variable的变量

tf.name_scope可以让变量有相同的命名，只是限于tf.Variable的变量

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))
a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.variable_scope('V2'):
a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')

with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a1.name
print a2.name
print a3.name
print a4.name

V1/a1:0
V1/a2:0
V2/a1:0
V2/a2:0

import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;

with tf.name_scope('V1'):
a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.name_scope('V2'):
a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')

with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a1.name
print a2.name
print a3.name
print a4.name


import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;

with tf.name_scope('V1'):
# a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.name_scope('V2'):
# a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')

with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
# print a1.name
print a2.name
# print a3.name
print a4.name


V1/a2:0
V2/a2:0

12-21 4667

12-06 6224

05-17 1万+

03-14 970

12-06 408

11-20 3905

06-21 102

03-19 2846

11-28 154

05-16 1万+

12-16 1万+

05-04 8164

05-16 2万+

09-19 8520

05-16 5万+

04-26 2521

06-05 6万+

01-16 3787

03-22 4万+

03-20 3万+

04-30 2万+

12-18 12万+

08-09 282

07-23 651

12-20 1万+

07-02 565

04-24 6990

06-17 899

03-19 906

05-08 4万+

05-06 3万+

04-21 52

03-25 2万+

01-16 2265

07-20 764

04-09 2万+

03-07 259

03-26 3万+

03-14 788

05-07 3万+

07-04 994

05-14 1万+

05-16 4670

05-22 2342

01-15 1238

03-31 4149

04-07 5万+

03-26 338

04-17 5万+

03-30 4万+

04-25 6万+

09-03 4万+

03-19 3万+

03-10 2万+

02-15 1万+

01-21 28万+

03-12 10万+

03-30 3924

07-05 900

03-10 12万+

02-14 7万+

07-03 453

02-13 28万+

03-04 13万+

03-23 54

03-25 8万+

04-29 3147

11-03 2万+

04-09 7万+

03-26 5286

05-21 3865

08-16 504

03-17 149

07-13 2万+

04-01 10万+

03-29 9万+

03-29 20万+

#### 面试了一个 31 岁程序员，让我有所触动，30岁以上的程序员该何去何从？

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客