2016-12-24 99 views
0

使用sess.run()我有一個問題,同時做一些簡單的計算,我的代碼如下圖所示:價值簡化版,改變Tensorflow

import tensorflow as tf 
import numpy as np 
#... 
Zeta=0.05 
Lambda=2**20 

step1 =sess.run(tf.matmul(x_k,alpha_T)) 
step2 =Lambda*step1 
step3 =Zeta+step2 
step1_2_3 = sess.run(Zeta + Lambda*tf.matmul(x_k,alpha_T)) 

print step1 
print step2 
print step3 
print step1_2_3 

,並打印出像:

[[ 1.60326695]] 
[[ 1681147.25]] 
[[ 1681147.3]] 
[[ 1681147.25]] 

看起來好像step1_2_3結合了step1,step2,step3

爲什麼不是step1_2_3[[ 1681147.3]]

+2

請包括x_k和alpha_T的定義,以便這將是一個可驗證的示例:http://stackoverflow.com/help/mcve – rofls

回答

0

我跑這個代碼:

import tensorflow as tf 
import numpy as np 

sess = tf.Session() 

x_k = np.array([[1.0]]) 
alpha_T = np.array([[1.60326695]]) 

Zeta = 0.05 
Lambda = 2**20 

step1 = sess.run(tf.matmul(x_k,alpha_T)) 
step2 = Lambda*step1 
step3 = Zeta+step2 
step1_2_3 = sess.run(Zeta + Lambda*tf.matmul(x_k,alpha_T)) 

print('step1', step1) 
print('step2', step2) 
print('step3', step3) 
print('step1_2_3', step1_2_3) 

它生產的:

('step1', array([[ 1.60326695]])) 
('step2', array([[ 1681147.2453632]])) 
('step3', array([[ 1681147.2953632]])) 
('step1_2_3', array([[ 1681147.2953632]])) 

好像它們是相同的我。也許你在某些代碼中沒有包含某些東西。