美文网首页Tensorflow
TensorFlow学习笔记(5)tf.rank, 求矩阵的维度

TensorFlow学习笔记(5)tf.rank, 求矩阵的维度

作者: 谢昆明 | 来源:发表于2018-11-09 09:21 被阅读3次

用例对应的源代码,觉得有帮助可以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

相关文章

网友评论

    本文标题:TensorFlow学习笔记(5)tf.rank, 求矩阵的维度

    本文链接:https://www.haomeiwen.com/subject/vqjnxqtx.html