第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Tensorflow 多項(xiàng)式數(shù)組

Tensorflow 多項(xiàng)式數(shù)組

SMILET 2021-12-17 15:46:17
我正在嘗試評(píng)估aX^2+bX+c,就像[a,b,c]\*[X*X X 1]在張量流中一樣。我試過以下代碼:import tensorflow as tfX = tf.placeholder(tf.float32, name="X")W = tf.Variable([1,2,1], dtype=tf.float32, name="weights")W=tf.reshape(W,[1,3])F = tf.Variable([X*X,X,1.0], dtype=tf.float32, name="Filter")F=tf.reshape(F,[3,1])print(W.shape)print(F.shape)Y=tf.matmul(W,F)with tf.Session() as sess:    sess.run(tf.global_variables_initializer())    for i in range(10):         sess.run(Y, feed_dict={X: i})    Y=sess.run(Y)print("Y:",Y)但是,初始化程序并不高興:(1, 3)(3, 1)...tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'X' with dtype float     [[{{node X}}]]During handling of the above exception, another exception occurred:...Caused by op 'X', defined at:  File "sample.py", line 2, in <module>    X = tf.placeholder(tf.float32, name="X")  ...關(guān)于可能的替代方案有什么想法嗎?
查看完整描述

2 回答

?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊

你只需要稍微修改一下代碼。的值不tf.Variable應(yīng)該是tf.placeholder,否則運(yùn)行時(shí)會(huì)導(dǎo)致你的初始化錯(cuò)誤sess.run(tf.global_variables_initializer())。你可以用tf.stack它來代替。另外,請(qǐng)記住在運(yùn)行時(shí)饋送數(shù)據(jù)sess.run(Y)。


import tensorflow as tf


X = tf.placeholder(tf.float32, name="X")

W = tf.Variable([1,2,1], dtype=tf.float32, name="weights")

W = tf.reshape(W,[1,3])

F = tf.stack([X*X,X,1.0])

F = tf.reshape(F,[3,1])

Y = tf.matmul(W,F)

with tf.Session() as sess:

    sess.run(tf.global_variables_initializer())

    for i in range(10):

        Y_val = sess.run(Y, feed_dict={X: i})

        print("Y:",Y_val)


Y: [[1.]]

Y: [[4.]]

Y: [[9.]]

Y: [[16.]]

Y: [[25.]]

Y: [[36.]]

Y: [[49.]]

Y: [[64.]]

Y: [[81.]]

Y: [[100.]]


查看完整回答
反對(duì) 回復(fù) 2021-12-17
?
MM們

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊

我認(rèn)為即使您仍然可以初始化一個(gè)依賴于這樣的占位符的變量,W除非您添加更多代碼來僅初始化未初始化的變量,否則將重復(fù)初始化。那是更多的努力。


希望我沒有錯(cuò)過這種方法的其他低效率。


import tensorflow as tf


sess = tf.InteractiveSession()


X = tf.placeholder(tf.float32, name="X")


W = tf.Variable([1, 2, 1], dtype=tf.float32, name="weights")

W = tf.reshape(W, [1, 3])


var = tf.reshape([X*X,X,1],[3,1])

F = tf.get_variable('F', dtype=tf.float32, initializer=var)


init = tf.global_variables_initializer()

Y=tf.matmul(W,F)


for i in range(10):

    sess.run([init], feed_dict={X: i})

    print(sess.run(Y))



[[1.]]

[[4.]]

[[9.]]

[[16.]]

[[25.]]

[[36.]]

[[49.]]

[[64.]]

[[81.]]

[[100.]]


查看完整回答
反對(duì) 回復(fù) 2021-12-17
  • 2 回答
  • 0 關(guān)注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)