tf.constant

匿名 (未验证) 提交于 2019-12-02 23:42:01
 

创建一个常数张量。得到的张量由类型为dtype的值填充,由参数值和(可选的)形状指定。参数值可以是常量值,也可以是类型为dtype的值列表。如果value是一个列表,那么列表的长度必须小于或等于shape参数所暗示的元素数量(如果指定)。如果列表长度小于按形状指定的元素数量,则列表中的最后一个元素将用于填充其余条目。参数形状是可选的。如果存在,它指定得到的张量的维数。如果不存在,则使用值的形状。如果未指定参数dtype,则从值的类型推断类型。

例:

 # Constant 1-D Tensor populated with value list. tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]  # Constant 2-D tensor populated with scalar value -1. tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.]                                              [-1. -1. -1.]]

返回值:

  • 一个恒定的张量。

返回值:

  • TypeError: if shape is incorrectly specified or unsupported.

https://tensorflow.google.cn/versions/r1.8/api_docs/python/tf/constant?hl=en

文章来源: https://blog.csdn.net/weixin_36670529/article/details/91549846
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!