通过with tf.Session() as sess: print (sess.run(y))即可打印出变量的值。下面给出例子import numpy as np
import tensorflow as tf
x = tf.constant([1,2,3,4,5,6])
y=tf.reshape(x,(2,3))
with tf.Session() as sess:
print (sess.run(y))2.在有的程序中需要使用如下init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
print(sess.run(y))
来查看张量,例子:
import numpy as np
import tensorflow as tf
x = tf.constant([1,2,3,4,5,6])
y=tf.reshape(x,[1,1,1,2,3])
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
print(sess.run(y))3.查看张量的大小。通过 变量名.shape即可显示,例子如下:import numpy as np
import tensorflow as tf
x = tf.constant([1,2,3,4,5,6])
y=tf.reshape(x,[1,1,1,2,3])
print (y.shape)以上是在python3以上版本运行
本文介绍如何在TensorFlow中进行张量的创建、重塑及打印操作,并展示了如何利用会话管理器初始化变量并获取张量的值。此外,还提供了查看张量维度的方法。
1362

被折叠的 条评论
为什么被折叠?



