tf.constant(value, dtype=None, shape=None, name='Const', verify_shape=False)###
Creates a constant tensor.
创建一个常量张量
The resulting tensor is populated with values of type dtype, as specified by arguments value and (optionally) shape (see examples below).
产生的张量为dtype类型,可指定参数如value和可选的shape(可查看下方的示例)
The argument value can be a constant value, or a list of values of type dtype. If value is a list, then the length of the list must be less than or equal to the number of elements implied by the shape argument (if specified). In the case where the list length is less than the number of elements specified by shape, the last element in the list will be used to fill the remaining entries.
value参数可以是一个常量值,或者一个dtype类型的值列表。如果value为一个列表,那么这个列表的长度必须小于或等于shape参数所指定的大小(如果设置shape的话)。当列表长度小于shape参数所指定的大小时,缺少的列表项会被填充为列表的最后一个参数。
The argument shape is optional. If present, it specifies the dimensions of the resulting tensor. If not present,the shape of value is used.
shape参数是可选的。如果存在该参数,它会指明生成的张量的维度。如果不存在,则使用value的shape。
If the argument dtype is not specified, then the type is inferred from the type of value.
如果参数dtype没有指定,那么会从value中自动推断出dtype的值。
For example:
# 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.]]
举例:
#使用值列表来填充一维的常量张量。tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]
#使用 -1 标量值来填充二维常量张量。tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.] [-1. -1. -1.]]
Args:
value: A constant value (or list) of output type dtype.
dtype: The type of the elements of the resulting tensor.
shape: Optional dimensions of resulting tensor.
name: Optional name for the tensor.
verify_shape: Boolean that enables verification of a shape of values.
参数:
value: 一个类型为dtype常量 (或常量列表)。
dtype: 指定生成的张量的类型。
shape: 可选参数, 指定生成的张量的维度。
name: 可选参数,指定生成的张量的名字。
verify_shape: 可选参数,布尔类型。 是否启用验证value的形状。
Returns:
A Constant Tensor.
返回值:
一个常量张量。