I ma trying to understand tf.rank function in tensorflow. From the documentation here, I understood that rank should return the number of distinct elements in the tensor.
Firstly, tf.rank
returns the dimension of a tensor, not the number of elements. For instance, the output from tf.rank
called for the 2x2 matrix would be 2.
To print the rank of a tensor, create an appropriate node, e.g. rank = tf.rank(x)
and then evaluate this node using a Session.run()
, as you've done for weights and x. Execution of print (tf.rank(x), tf.rank(weights))
expectedly prints out description of tensors, as tf.rank(x), tf.rank(weights)
are nodes of the graph, not the variables with defined values.