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}))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM