张量
代码
import tensorflow as tf
# 变量op
# 1、变量能够持久化保存,普通张量op是不行的
# 2、当定义一个变量op的时候,一定要在会话当中去运行初始化
g = tf.Graph()
with g.as_default():
c = tf.constant(11.0)
print(c.graph)
a = tf.constant(5.0)
b = tf.constant(6.0)
sum1 = tf.add(a, b)
# 默认的这张图,相当于是给程序分配一段内存
graph = tf.get_default_graph()
print(graph)
# var = tf.Variable(tf.random_normal([2,3],mean=0.0,stddev=1.0))
# print(a, var)
#必须做一步显示的初始化
init_op = tf.global_variables_initializer()
plt = tf.placeholder(tf.float32, [None, 3])
print(plt)
plt.set_shape([3, 2])
print(plt)
plt_reshape = tf.reshape(plt, [2, 3])
print(plt_reshape)
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
print(sess.run(plt, feed_dict={plt: [[1, 2, 3],[4, 5, 36],[2, 3, 4]]}))
print(a.graph)
print("--------")
print(a.shape)
print(plt.shape)
print("---------")
print(a.name)
print("---------")
print(a.op)