Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
tf.rank function
Function Description:
tf.rank to return tensor of rank
Note: rank tensor rank of the matrix is not the same tensor rank is the number required for each element of the index only option tensor of rank, also known as to "order", "degree" or "ndims".
rank(
input,
name=None
)
Description:
Here tensor of rank, can be directly understood dimension, that this tensor is a few-dimensional, it is not the rank of the matrix is not the shape of the array, simple to understand, it is possible the number of layers in brackets
Example:
x1 = tf.constant([1, 2, 4]) # 1x3
x2 = tf.constant([[1, 2, 4], [8, 16, 32]]) # 2x3
x3 = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]) # 1x2x3
with tf.Session() as sess:
print(sess.run(tf.rank(x1))) # 1
print(sess.run(tf.rank(x2))) # 2
print(sess.run(tf.rank(x3))) # 3