zoukankan      html  css  js  c++  java
  • tensorflow中的函数获取Tensor维度的两种方法:

    获取Tensor维度的两种方法:

    Tensor.get_shape()

    返回TensorShape对象,

    如果需要确定的数值而把TensorShape当作list使用,肯定是不行的。

    需要调用TensorShape的as_list()方法,

    需要调用TensorShape.as_list()方法来获取维度数值。

    来实践一下:

    import tensorflow as tf
    a = tf.zeros(shape=[10,20])
    b = a.get_shape()
    c = b.as_list()
    print(b)
    print(c)

    输出结果:

    (10, 20)
    [10, 20]

    Tensorflow.shape()

    返回Tensor对象,需要调用Session.run()方法来获取维度数值。

  • 相关阅读:
    第六周 8.23-8.29
    Go-ethereum源码解析-Part I
    Go语言
    UVa Live 4725
    UVa 11134
    UVa 11100
    UVa 11627
    UVa Live 4794
    UVa LA 4254
    UVa 10905
  • 原文地址:https://www.cnblogs.com/qqw-1995/p/9670761.html
Copyright © 2011-2022 走看看