TensorFLow 函数翻译 — tf.constant()

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参数是可选的。如果存在该参数,它会指明生成的张量的维度。如果不存在,则使用valueshape

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.

返回值:
一个常量张量。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 丸子即将开始她的异国求学经历,在此之前,留下种种记忆,展示她成长的点滴。不管她长多大,飞多远,她始终是我心底那个可...
    Kathryn_Lei教练阅读 2,900评论 2 8
  • 羽乐圈注册流程优化设计 注册是用户深度使用产品的必要过程,是一个平台的门户,它的设计姿态就是对待用户的态度,举足轻...
    LeifTan阅读 3,712评论 0 3
  • 我是日记星球166号星宝宝~媛珂,正在参加小牛妈妈的日记星球21天蜕变之旅的写作训练!这是我的第31篇原创日记!我...
    媛珂阅读 4,421评论 2 3