zoukankan      html  css  js  c++  java
  • tf.constant

    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).

    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.

    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.

    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.

    Returns:

    A Constant Tensor.

    Raises:

    • TypeError: if shape is incorrectly specified or unsupported.
     1 #!/usr/bin/env python3
     2 #-*- coding:utf-8 -*-
     3 ############################
     4 #File Name: tensor_constant.py
     5 #Author: frank
     6 #Mail: frank0903@aliyun.com
     7 #Created Time:2018-05-30 23:02:38
     8 ############################
     9 import tensorflow as tf
    10 
    11 ct = tf.constant([1.,2.,3])
    12 print(ct)
    13 print(ct.shape)
    14 print(ct.name)
    15 
    16 ct2 = tf.constant([1,2,3], shape=(2, 3))
    17 print(ct2)
    18 
    19 with tf.Session() as sess:              
    20     sess.run(ct)
    21     print(ct.eval())
    22     print(ct2.eval())






    0 表示 节点名

    1 表示 一维数组

    2 表示 数据类型,同时可以看出是根据数据的值来推断数据类型

    3 表示 2行3列的矩阵

    6 表示 当元素的个数 少于 shape定义的个数时,由最后一个元素的值初始化其他空位元素

     
  • 相关阅读:
    struct
    python Hbase Thrift pycharm 及引入包
    python 性能鸡汤
    hbase 0.96 单机伪分布式配置文件及遇到的问题 find命令
    ubuntu下配置protobuf
    hadoop 2.2.0 eclipse 插件编译 及相关eclipse配置图解
    hadoop2.2.0 单机伪分布式(含64位hadoop编译) 及 eclipse hadoop开发环境搭建
    install ubuntu
    ubuntu wubi安装注意事项
    HBase eclipse开发环境搭建
  • 原文地址:https://www.cnblogs.com/black-mamba/p/9114285.html
Copyright © 2011-2022 走看看