2017-12-20 5 views
0

テンソルフローが新しく、あなたが私を助けてくれることを願っています。テンソルフローL2ノルム

2つのベクトル(x [0] - y [0])*(x [0] - y [0])+(x [1] - y [1] *(X [1] - Y [1])+ ...ここで

は私のコードです:

import tensorflow as tf; 

sess=tf.InteractiveSession() 

xx = [[1.0, 2.0, 3.0]]; 
yy = [[2.0, 3.0, 4.0]]; 
x = tf.placeholder(tf.float32, shape=[1, 3], name='x') 
y = tf.placeholder(tf.float32, shape=[1, 3], name='y') 
cost = tf.nn.l2_loss(x - y, name='cost') 

sess.run([cost, y], feed_dict={x: xx, y:yy}) 
print(cost, y); 

But here is the output 

Tensor("cost:0", shape=(), dtype=float32) Tensor("y:0", shape=(1, 3), dtype=float32). 

は、どのように私は実際に値をプリントアウトすることができますか?

おかげで、

答えて

1

あなたはsess.runから返された値を解凍する必要があります。

cost_, y_ = sess.run([cost, y], feed_dict={x: xx, y:yy}) 
print(cost_, y_); 

# 1.5 [[ 2. 3. 4.]] 
+0

それは働きました。どうもありがとうございました – fireman

関連する問題