用例对应的源代码,觉得有帮助可以Star
import tensorflow as tf
# tf.rank(
# input,
# name=None
# )
#
# Returns the rank of a tensor.
# 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.
x = tf.constant([[1, 2, 4]]) # 2x2 matrix
x2 = tf.constant([[1, 2, 4], [8, 16, 32]]) # 2x2 matrix
x3 = tf.constant([1, 2, 4]) # 1x1 matrix
with tf.Session() as sess:
print(sess.run(tf.rank(x))) # 2
print(sess.run(tf.rank(x2))) # 2
print(sess.run(tf.rank(x3))) # 1