# 常量与变量
def var_demo():
# 1变量
a1 = tf.Variable(tf.linspace(-5.0, 5.0, 10), dtype=tf.float32)
# c = tf.cast(a, dtype=tf.float64)
# b = np.linspace(-5.0, 5.0, 10)
# init = tf.global_variables_initializer()
# sess = tf.Session()
# sess.run(init)
# print(sess.run(c))
# print(b) np 不需要Session会话框
# 2
# a = tf.Variable(tf.random_normal([3, 3], mean=1.0, stddev=2.0, dtype=tf.float32), dtype=tf.float32)
# 3
# b = tf.Variable(a.initialized_value(), dtype=tf.float32)
# 4
# d = tf.Variable(tf.zeros([5, 6, 4], dtype=tf.float32), dtype=tf.float32)
# 5
# c = tf.assign(a1, tf.linspace(-1., 1., 10))
# init = tf.global_variables_initializer()
# f = tf.cast(c, dtype=tf.int32)
# sess = tf.Session()
# sess.run(init)
# print(sess.run(a))
#常量
# c2 = tf.constant(3)
# c3 = tf.constant([2, 3])
# sess = tf.Session()
# print(sess.run(c3))
# var_demo()
# def ops_demo():
# 操作数
# 矩阵别少了括号
# a = tf.constant([[1, 2, 3], [4, 5, 6]])
# b = tf.constant(4)
# c = tf.Variable(tf.random_normal([2, 3], 1.0, 3.0), dtype=tf.float32)
# d = tf.add(c, tf.cast(tf.divide(a, b), dtype=tf.float32))
# m1 = tf.Variable(tf.random_normal([3, 3], 1.0, 3.0), dtype=tf.float32)
# m2 = tf.Variable(tf.random_normal([3, 3], 3.0, 1.0), dtype=tf.float32)
# mm = tf.matmul(m1, m2)
# 占位符
# x = tf.placeholder(shape=[3, 3], dtype=tf.float32)
# y = tf.placeholder(shape=[3, 2], dtype=tf.float32)
# xy = tf.matmul(x, y)
# m3 = tf.add(m1, m2)
# m4 = tf.subtract(m1, m2)
# m5 = tf.divide(m1, m2)
# m6 = tf.multiply(m1, m2)
# init = tf.global_variables_initializer()
# sess = tf.Session()
# sess.run(init)
# result = sess.run([m3, m4, m5, m6])
# result = sess.run(xy, feed_dict={x: [[1, 1, 1], [2, 2, 2], [3, 3, 3]], y: [[4, 4], [5, 5], [6, 6]]})
# print(result)
# #print(sess.run(mm))
# ops_demo()