我想检查张量的等级。下面是我的代码:
import tensorflow as tf
x = tf.constant([[0,1,0], [0,1,0]])
print(tf.rank(x))它回来了
Tensor("Rank_14:0", shape=(), dtype=int32)Rank_14:0不断增长的地方。我希望它还能回来。我做错什么了?
发布于 2017-09-27 14:28:47
Rank_14:0是返回的张量的名称,而不是它的值,您需要在会话中计算张量以获得实际值:
with tf.Session() as sess:
sess.run(tf.rank(x))import tensorflow as tf
x = tf.constant([[0,1,0], [0,1,0]])
r = tf.rank(x)
sess = tf.InteractiveSession()
print("My tensor is: ", r)
print("The value of my tensor is: ", r.eval())
My tensor is: Tensor("Rank_3:0", shape=(), dtype=int32)
The value of my tensor is: 2https://stackoverflow.com/questions/46450320
复制相似问题