【发布时间】:2017-03-04 21:08:28
【问题描述】:
我想了解 tensorflow 中的 tf.rank 函数。从文档here 中,我了解到 rank 应该返回张量中不同元素的数量。
这里 x 和权重是 2 个不同的 2*2 张量,每个张量有 4 个不同的元素。但是,rank() 函数的输出是:
Tensor("Rank:0", shape=(), dtype=int32) Tensor("Rank_1:0", shape=(), dtype=int32)
另外,对于张量 x,我使用 tf.constant() 和 dtype = float 将 ndarray 转换为 float32 张量,但 rank() 仍然输出为 int32。
g = tf.Graph()
with g.as_default():
weights = tf.Variable(tf.truncated_normal([2,2]))
x = np.asarray([[1 , 2], [3 , 4]])
x = tf.constant(x, dtype = tf.float32)
y = tf.matmul(weights, x)
print (tf.rank(x), tf.rank(weights))
with tf.Session(graph = g) as s:
tf.initialize_all_variables().run()
print (s.run(weights), s.run(x))
print (s.run(y))
我应该如何解释输出。
【问题讨论】:
标签: tensorflow