带变量创建的Tensorflow While循环

2024-09-30 08:27:27 发布

您现在位置:Python中文网/ 问答频道 /正文

Tensorflow While循环的变量创建代码如下:

x = tf.Variable(100)    
c = tf.Constant(2)    
n = 100    
loops = 50

l1 = tf.Variable(np.random.random(n))    
c1 = tf.Variable(np.random.random(n))     
x = tf.multiply(c1,tf.exp(-(x-l1)/c))

l2 = tf.Variable(np.random.random(n))
c2 = tf.Variable(np.random.random(n)) 
x = tf.multiply(c2,tf.exp(-(x-l2)/c))

l3 = tf.Variable(np.random.random(n))
c3 = tf.Variable(np.random.random(n))
x = tf.multiply(c3,tf.exp(-(x-l3)/c))

.....

.....

l50 = tf.Variable(np.random.random(n))
c50 = tf.Variable(np.random.random(n))
x = tf.multiply(c50,tf.exp(-(x-l50)/c))

所以,我想在tensorflow的while循环中这样做:

^{pr2}$


如何在tensorflow中实现这一点。 谢谢你


Tags: l1tftensorflownprandomvariablemultiplyc2
1条回答
网友
1楼 · 发布于 2024-09-30 08:27:27

你能这样喂它吗?在

l = tf.placeholder(tf.float32, shape=[None, ])
c = tf.placeholder(tf.float32, shape=[None, ])

sess = tf.Session()
sess.run(tf.global_variables_initializer())

x = tf.multiply(l,c)   #Assume a formula

for i in range(50) :
    arr = np.random.random_sample((i,))
    print (arr)
    sess.run(x,feed_dict={l :arr,c :arr})

根据你的评论,我只是试图。这不是确切的答案。在

^{pr2}$

相关问题 更多 >

    热门问题