tf.constant

tf.constant(value,dtype=None,shape=None,name='Const',verify_shape=False
)

Defined in tensorflow/python/framework/constant_op.py.

See the guide: Constants, Sequences, and Random Values > Constant Value Tensors

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.
参数值可以是常量值,也可以是dtype类型的值列表。
如果value是一个列表,则列表的长度必须小于或等于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.
参数形状是可选的。 如果存在,它指定所得张量的尺寸。 如果不存在,则使用值的形状。

If the argument dtype is not specified, then the type is inferred from the type of 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.]]

tf.constant differs from tf.fill in a few ways:
tf.constant与tf.fill在以下方面有所不同:

  • tf.constant supports arbitrary constants, not just uniform scalar Tensors like tf.fill.
    tf.constant支持任意常量,而不仅仅是像tf.fill这样的统一标量张量。

  • tf.constant creates a Const node in the computation graph with the exact value at graph construction time. On the other hand, tf.fill creates an Op in the graph that is expanded at runtime.
    tf.constant在计算图中使用图构建时的确切值创建一个Const节点。 另一方面,tf.fill在图形中创建一个Op,并在运行时对其进行扩展。

  • Because tf.constant only embeds constant values in the graph, it does not support dynamic shapes based on other runtime Tensors, whereas tf.fill does.
    因为tf.constant仅将常数值嵌入到图形中,所以它不支持基于其他运行时Tensor的动态形状,而tf.fill则支持。

Args:

  • value: A constant value (or list) of output type dtype.
    输出类型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.
    布尔值,用于验证值的形状。

Returns:

  • A Constant Tensor.
    恒定张量。

Raises:

  • TypeError: if shape is incorrectly specified or unsupported.
    TypeError:如果形状指定不正确或不受支持。

20200212

tf.constant()返回的结果是一个Tensor对象

import tensorflow as tf
x = tf.constant([[1., 1.], [2., 2.]])
print(type(x))

结果:<class ‘tensorflow.python.framework.ops.Tensor’>

tensorflow1.11.0 tf.constant()函数(创建一个常数张量)相关推荐

  1. 在python中元素是无序不重复的_set()函数~~创建一个无序不重复元素集

    set()函数~~创建一个无序不重复元素集 2020-08-11 11:49常用函数 本篇文章里小编给大家分享了关于Python中set()函数的相关知识点内容,set() 函数用于创建一个无序不重复 ...

  2. python自定义一个函数求序列中的偶数_使用range函数创建一个从2到10的偶数列表 alist...

    [多选题]在Python中添加注释可以使用哪些符号? [简答题]给定一个包含若干个整数的列表alist,要求返回输出列表blist,blist中的元素为 与alist对应位置上的元素之外其余各元素的乘 ...

  3. 关于VC++6.0中getline函数的一个bug

    关于VC++6.0中getline函数的一个bug 最近在调试程序时,发现getline函数在VC++6.0和其他编译器上运行结果不一样,比如有如下这段程序: #include <iostrea ...

  4. R语言使用magick包的image_animate函数和image_morph函数创建一个由n个图像组成的序列,逐渐将一个图像转换成另一个图像(sequence of image morph by)

    R语言使用magick包的image_animate函数和image_morph函数创建一个由n个图像组成的序列,逐渐将一个图像转换成另一个图像(Creates a sequence of n ima ...

  5. WF4.0入门系列1——创建一个简单的工作流

    WF4.0入门系列1--创建一个简单的工作流 打开VS2010,选择文件-新建-项目,选择Workflow项 工作流台应用程序,在名称处输入chapter01,选择合适的位置,这里默认,单击确定. V ...

  6. [Python] set()函数 创建一个无序不重复元素集

    Python set()函数 创建一个无序不重复元素集 功能: set()函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集.差集.并集等. 语法: class set([it ...

  7. js练习题:构建函数创建一个电脑对象

    js练习题:构建函数创建一个电脑对象 该对象有颜色,重量,品牌,型号,可以看电影,听音乐,打游戏和敲代码. function Computer(color,weight,brand,model){th ...

  8. Scott Mitchell 的ASP.NET 2.0数据教程之一: 创建一个数据访问层

    原文 | 下载本教程中的编码例子 | 下载本教程的英文PDF版 导言 作为web开发人员,我们的生活围绕着数据操作.我们建立数据库来存储数据,写编码来访问和修改数据,设计网页来采集和汇总数据.本文是研 ...

  9. 【tensorflow】tf.reshape函数说明:重塑张量

    转载 [471]tf.reshape函数说明_周小董-CSDN博客 https://blog.csdn.net/xc_zhou/article/details/85342542 函数原型: tf.re ...

最新文章

  1. intellij idea 生成可执行jar 运行提示没有主清单属性
  2. 基于Redis实现分布式锁
  3. python散点图拟合曲线-python散点图:如何添加拟合线并显示拟合方程与R方?
  4. java.util.list 赋值_java.util(ArrayList)
  5. 在ASP.NET页面中实现数据柱状图
  6. python基础-------python2.7教程学习【廖雪峰版】(二)
  7. 如何按 value 对 dictionary 进行排序?
  8. ssis 计划任务_SSIS Web服务任务
  9. sql crud_使用适用于SQL Server的Python SQL库执行CRUD操作
  10. easyUI的使用.datagrid()生成列表日期时间显示异常,一个方法带入有效修复
  11. windows系统 Git Server git服务器自己搭建 (基于 Gitblit or Gogs )
  12. [C/C++] ccpuid:CPUID信息模块 V1.02版,支持Mac OS X,支持纯C,增加CPUF常数
  13. 天堂2地点坐标(SQL语句,可直接导入数据库)
  14. cicso+RHEL7实践——小型校园网的搭建
  15. EF CORE DELETE
  16. Gabor滤波器 pytorch实现
  17. Android开发支付集成——微信集成
  18. 如何检查电脑端安装的Flash Activex 控件版本?
  19. 【CTFSHOW】web入门 NodeJS
  20. 美国高通公司开发出了新的指纹识别技术

热门文章

  1. PM——【1】维护功能位置主数据
  2. 采购寄售业务的系统实现
  3. 【ABAP】Native SQL
  4. 欧锦赛球星谱:帕克领豪阵 诺天王对决加索尔
  5. SAP,IBM,AC实施之比较
  6. 物料价格分析取未分摊和未分配价格差异
  7. 做好新型冠状病毒防疫 |春节第一重任:说服爸妈带口罩
  8. 从《我要投资》,看麓谷基金广场的“孤峰优势”
  9. 干掉耐克的,绝不会是下一个耐克?
  10. 后疫情时代,乳企如何迎来下一个风口?