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. Django运算符表达式

    在html页面中,加入运算符表达式,进行逻辑判断.可参考手册.我用的Django是2.1版本 view.py中的代码: from django.shortcuts import render from ...

  2. linux:echo命令示例

    echo命令:用于字符串的输出  $echo string 1.打印普通字符串 $echo "hello kumata" hello kumata #这里的双引号完全可以省略,以下 ...

  3. 教程 | 如何使用纯NumPy代码从头实现简单的卷积神经网络

    Building Convolutional Neural Network using NumPy from Scratch https://www.linkedin.com/pulse/buildi ...

  4. 2018/03/20 每日一个Linux命令 之 cp

    cp 命令用于复制文件/目录 cp [-参数] [复制文件] [复制成为的新文件] 参数(这里只介绍平常会用到的,之后的话遇到再回来补充) -f 覆盖已经存在的目标文件而不给出提示. -i 与-f选项 ...

  5. Python yield 使用浅析(转)

    add by zhj: 说到yield,就要说说迭代器.生成器.生成器函数. 迭代器:其实就是一个可迭代对象,书上说迭代器,我个人不喜欢这个说法,有点晦涩.可迭代对象基本上可以认为是有__iter__ ...

  6. struts2 错误:Dispatcher initialization failed java.lang.RuntimeException

    严重: Dispatcher initialization failed java.lang.RuntimeException: java.lang.reflect.InvocationTargetE ...

  7. 虫师的性能测试思想html网页学习

    http://www.cnblogs.com/fnng/category/387349.html

  8. 编码问题:python写入文件

    方法一:(推荐) line1 = "我爱中国111" line2 = u"我爱祖国222" with open('1.txt','w',encoding='ut ...

  9. 前端 HTML文档结构介绍

    <!DOCTYPE HTML> <html> <head>...</head> <body>...</body> </ht ...

  10. Spark2.x学习笔记:Spark SQL快速入门

    Spark SQL快速入门 本地表 (1)准备数据 [root@node1 ~]# mkdir /tmp/data [root@node1 ~]# cat data/ml-1m/users.dat | ...