tf.placeholder(dtype, shape=None, name=None)

placeholder,占位符,在tensorflow中类似于函数参数,运行时必须传入值。

  • dtype:数据类型。常用的是tf.float32,tf.float64等数值类型。
  • shape:数据形状。默认是None,就是一维值,也可以是多维,比如[2,3], [None, 3]表示列是3,行不定。
  • name:名称。

代码片段-1(计算3*4=12)

  1. #!/usr/bin/env python
  2. # _*_ coding: utf-8 _*_
  3. import tensorflow as tf
  4. import numpy as np
  5. input1 = tf.placeholder(tf.float32)
  6. input2 = tf.placeholder(tf.float32)
  7. output = tf.multiply(input1, input2)
  8. with tf.Session() as sess:
  9. print sess.run(output, feed_dict = {input1:[3.], input2: [4.]})

代码片段-2(计算矩阵相乘,x*x)

    1. #!/usr/bin/env python
    2. # _*_ coding: utf-8 _*_
    3. import tensorflow as tf
    4. import numpy as np
    5. x = tf.placeholder(tf.float32, shape=(1024, 1024))
    6. y = tf.matmul(x, x)
    7. with tf.Session() as sess:
    8. #  print(sess.run(y))  # ERROR: x is none now
    9. rand_array = np.random.rand(1024, 1024)
    10. print(sess.run(y, feed_dict={x: rand_array}))  # Will succeed.

tf.placeholder使用说明的更多相关文章

  1. TensorFlow 辨异 —— tf.placeholder 与 tf.Variable

    https://blog.csdn.net/lanchunhui/article/details/61712830 https://www.cnblogs.com/silence-tommy/p/70 ...

  2. 深度学习原理与框架-Tensorflow基本操作-变量常用操作 1.tf.random_normal(生成正态分布随机数) 2.tf.random_shuffle(进行洗牌操作) 3. tf.assign(赋值操作) 4.tf.convert_to_tensor(转换为tensor类型) 5.tf.add(相加操作) tf.divide(相乘操作) 6.tf.placeholder(输入数据占位

    1. 使用tf.random_normal([2, 3], mean=-1, stddev=4) 创建一个正态分布的随机数 参数说明:[2, 3]表示随机数的维度,mean表示平均值,stddev表示 ...

  3. tf.placeholder

    tf.placeholder placeholder( dtype, shape=None, name=None ) 功能说明: 是一种占位符,在执行时候需要为其提供数据 参数列表: 参数名 必选 类 ...

  4. TensorFlow函数(一)tf.placeholder()函数

    tf.placeholder(dtype, shape=None, name=None) 此函数用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.float32,tf ...

  5. Tensorflow函数——tf.placeholder()函数

    tf.placeholder()函数 Tensorflow中的palceholder,中文翻译为占位符,什么意思呢? 在Tensoflow2.0以前,还是静态图的设计思想,整个设计理念是计算流图,在编 ...

  6. tf.placeholder类似函数中的形参

    tf.placeholder(dtype, shape=None, name=None) 此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.fl ...

  7. tf.Variable()、tf.get_variable()和tf.placeholder()

    1.tf.Variable() tf.Variable(initializer,name) 功能:tf.Variable()创建变量时,name属性值允许重复,检查到相同名字的变量时,由自动别名机制创 ...

  8. tf.placeholder函数说明

    函数形式: tf.placeholder(     dtype,     shape=None,     name=None ) 参数: dtype:数据类型.常用的是tf.float32,tf.fl ...

  9. tensorflow学习之tf.placeholder

    placeholder函数相当于一个占位符,tf.placeholder(dtype, shape=None, name=None) dtype:数据类型.常用的是tf.float32,tf.floa ...

随机推荐

  1. Python面向对象:获取对象信息

    学习笔记内容简介: 获取对象属性和方法的函数: type(): 判断对象类型 isinstance() : 判断class的类型 dir() : 获得一个对象的所有属性和方法 把属性和方法列出来是不够 ...

  2. h5直播

    直播开发之旅 ① 状态控制: 目前我们先考虑直播的三种状态: 直播前,直播中,结束. 针对每个状态我们肯定会有不同的显示,这三种状态可以是三个页面,相互切换,或者一个页面,控制页面相关隐藏和显示. 可 ...

  3. 使用VS Code编译运行C/C++程序

    使用VS Code编译运行C/C++程序 - qq_435248055的博客 - CSDN博客 https://blog.csdn.net/qq_31823267/article/details/78 ...

  4. 44(function pointer 2)

    #include<iostream> using namespace std; class A { public: int x; int sayhello() { cout<< ...

  5. grafana,graphite,influxdb with docker

    ++++++++++++++++++++++++ sudo docker pull tutum/influxdb sudo docker run -d -p 8083:8083 -p8086:8086 ...

  6. JQUERY中各个ajax函数

    1.$(selecter).load()     --- load() 方法从服务器加载数据,并把返回的数据放入被选元素中 2.$.get(url,callback()) 3.$.post(url,d ...

  7. 转:数据库范式(1NF 2NF 3NF BCNF)

    数据库的设计范式是数据库设计所需要满足的规范,满足这些规范的数据库是简洁的.结构明晰的,同时,不会发生插入(insert).删除(delete)和更新(update)操作异常.反之则是乱七八糟,不仅给 ...

  8. operator, itertools

    import operator import itertools info_list = [ {'name': 'Quinn', 'age': 50}, {'name': 'Ryan', 'age': ...

  9. JAVA队列的使用

    JAVA队列的使用 今天跟大家来看看如何在项目中使用队列.首先我们要知道使用队列的目的是什么?一般情况下,如果是一些及时消息的处理,并且处理时间很短的情况下是不需要使用队列的,直接阻塞式的方法调用就可 ...

  10. 论存储IOPS和Throughput吞吐量之间的关系

    论存储IOPS和Throughput吞吐量之间的关系 http://www.csdn.net/article/2015-01-14/2823552 IOPS和Throughput吞吐量两个参数是衡量存 ...