0

The TF documentation says that running these two lines

t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
tf.rank(t)

should return 3, as the tensor rank is 3. However, it returns

<tf.Tensor 'Rank_1:0' shape=() dtype=int32>

The documentation also says the rank function is equivalent to numpy's ndim so I ran it over the given array and it does return 3.

Is there any reason for this problem? I am using the integrated Ipython console in Spyder; python 3.5

Andre P.
  • 1
  • 1

1 Answers1

0

Seems like I did not understand the inner workings of TensorFlow yet. As I had read, tf.Tensors do not have values assigned to them. They are merely graphs to be computed later on. What I did not know is that they are computed only after a tf.Session() call. Running the session to calculate the rank did yield the correct "3"

The answer was found in the following question tf.rank function in Tensorflow

Andre P.
  • 1
  • 1
  • You may be interested in TensorFlow's [eager execution](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/g3doc/guide.md), which will run operations immediately and make the `Tensor` objects contain concrete values. – ash Feb 18 '18 at 06:21
  • Tensors are outputs of **nodes** in a graph and not a graph! – Patwie Feb 18 '18 at 09:54