Python 如何使用tf.print()在张量内打印3个以上的值?
我有一个简单的代码,用于将张量沿Python 如何使用tf.print()在张量内打印3个以上的值?,python,tensorflow,Python,Tensorflow,我有一个简单的代码,用于将张量沿轴=1拆分为三部分 sess = tf.Session() a = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) x, y, z = tf.split(a, 3, axis=1) print_out_x = tf.Print(x, [x], message='Value of x: ', name='x_value') print_out_y = tf.Print(y, [y], me
轴=1拆分为三部分
sess = tf.Session()
a = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
x, y, z = tf.split(a, 3, axis=1)
print_out_x = tf.Print(x, [x], message='Value of x: ', name='x_value')
print_out_y = tf.Print(y, [y], message='Value of y: ', name='y_value')
print_out_z = tf.Print(z, [z], message='Value of z: ', name='z_value')
sess.run([print_out_x, print_out_y, print_out_z])
print(print_out_x)
print(print_out_y)
print(print_out_z)
我得到的输出如下
如何使用tf.Print()
,而不是…
来获取x、y、z中的全部值?更具体地说,我希望输出应该是
Value of z: [[3][6][9][12]]
Value of y: [[2][5][8][11]]
Value of x: [[1][4][7][10]]
您可以使用tf.Print()
函数中的:summary
,设置每个输入张量需要打印的参数数
例如
tf.Print(x, [x],summarize=x.shape[0], message='Value of x: ', name='x_value')
#Value of x: [[1][4][7][10]]
您可以使用tf.Print()
函数中的:summary
,设置每个输入张量需要打印的参数数
例如
tf.Print(x, [x],summarize=x.shape[0], message='Value of x: ', name='x_value')
#Value of x: [[1][4][7][10]]