创建一个常数张量。得到的张量由类型为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