美文网首页
tensorflow.shape() 函数用法

tensorflow.shape() 函数用法

作者: 上善若水_飘 | 来源:发表于2020-09-23 10:30 被阅读0次

    # tf.shape()  返回的是tensor的维度

    代码如下:


    import tensorflow as tf     #导入tensorflow包

    # 定义一个tensor,是由2行4列构成 类型为:float32

    constant_tensor=tf.constant(value=[[1.1,2.2,3.3,4.4],[4.1,3.1,2.1,1.1]], dtype=tf.float32)

    # shape函数是现实tensor的维度结构

    shape_constant_tensor=tf.shape(constant_tensor)

    # 定义一个Session

    sess=tf.Session()

    # 运行这个Session

    sess.run(shape_constant_tensor)


    输出结果:

    array([2, 4]

    恭喜您学习完成!

    相关文章

      网友评论

          本文标题:tensorflow.shape() 函数用法

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