zoukankan      html  css  js  c++  java
  • 2.6 tensorflow2.3学习--占位符placeholder

    自己开发了一个股票智能分析软件,功能很强大,需要的点击下面的链接获取:

    https://www.cnblogs.com/bclshuai/p/11380657.html

    1.1  占位符placeholder

    1.1.1         占位符介绍

    占位符。这是一个在定义时不需要赋值,但在使用之前必须赋值(feed)的变量,可以用数据通过feed_dict给填充进去就可以,通常用作训练数据。

    tf.placeholder(dtype, shape=None, name=None)

    placeholder,占位符,在tensorflow中类似于函数参数,运行时必须传入值。

    dtype:数据类型。常用的是tf.float32,tf.float64等数值类型。

    shape:数据形状。默认是None,就是一维值,也可以是多维,比如[2,3], [None, 3]表示列是3,行不定。

    name:名称。

    使用实例

    d50 = tf.compat.v1.placeholder(tf.float32, name="input1")#2.0tensorflow无placeholder
    d51 = tf.sin(d50)
    print(ss.run(d51, feed_dict={d50: 3.1415926/2}))#1.0

    1.1.2         占位符运算

    import tensorflow as tf

    # 使用变量(variable)作为计算图的输入

    # 构造函数返回的值代表了Variable op的输出 (session运行的时候,为session提供输入)

    # tf Graph input

    a = tf.placeholder(tf.int16)

    b = tf.placeholder(tf.int16)

    # 定义一些操作

    add = tf.add(a, b)

    mul = tf.multiply(a, b)

    # 启动默认会话

    with tf.Session() as sess:

        # 把运行每一个操作,把变量值输入进去

        print("变量相加: %i" % sess.run(add, feed_dict={a: 2, b: 3}))

        print("变量相乘: %i" % sess.run(mul, feed_dict={a: 2, b: 3}))

  • 相关阅读:
    Cg学习
    Unity URP
    unity官方案例水效果解析
    Unity使用Xlua框架热更
    隐私政策以及用户协议
    iOS App 从点击到启动
    iOS编程中throttle那些事
    Homebrew安装
    ios 开发证书 appids 描述文件关系
    学习网站
  • 原文地址:https://www.cnblogs.com/bclshuai/p/13978984.html
Copyright © 2011-2022 走看看