TensorFlow学习笔记-变量、常量、操作符

# 常量与变量
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()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值