tensorflow打印输出L2范数

tensorflow打印输出L2范数,tensorflow,norm,Tensorflow,Norm,我是tensorflow的新手,希望你能帮助我 我想打印出两个向量(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')

我是tensorflow的新手,希望你能帮助我

我想打印出两个向量(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). 
如何打印出实际值


谢谢,

您需要解压缩sess中返回的值。运行

cost,y=sess.run([cost,y],feed_dict={x:xx,y:yy})
打印(成本,y);
# 1.5 [[ 2.  3.  4.]]