2017-09-27 3 views
0

テンソルのランクを確認したいと思います。ここでそれを行うには、私のコードは次のとおりです。テンソルフロー:テンソルランクを確認

import tensorflow as tf 
x = tf.constant([[0,1,0], [0,1,0]]) 
print(tf.rank(x)) 

それはRank_14:0が増え続け

Tensor("Rank_14:0", shape=(), dtype=int32) 

を返します。 私はそれが2を返すことを期待しています。私は間違って何をしていますか?

答えて

1

Rank_14:0は返さテンソルの名前ではない、それは価値だ、あなたは実際の値を取得するには、Sessionにテンソルを評価する必要があります。

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: 2 
関連する問題