import tensorflow as tf
import numpy as np

1.tf.placeholder

placeholder()函数是在神经网络构建graph的时候在模型中的占位,此时并没有把要输入的数据传入模型,它只会分配必要的内存

等建立session,在会话中,运行模型的时候通过feed_dict()函数向占位符喂入数据。

2.tf.session

1.tf.multiply 点乘

input1 = tf.placeholder(tf.float32)

input2 = tf.placeholder(tf.float32)

output = tf.multiply(input1, input2)

with tf.Session() as sess:
     print(sess.run(output, feed_dict = {input1:[3.], input2: [4.]}))  --[12.]

2.tf.matmul 矩阵相乘

x = tf.placeholder(tf.float32, shape=(3, 3))
   y = tf.matmul(x, x)

with tf.Session() as sess:
  #print(sess.run(y)) # ERROR:此处x还没有赋值
  rand_array = np.random.rand(3, 3)
  print("rand_array",rand_array)
  print(sess.run(y, feed_dict={x: rand_array}))

tf.matmul / tf.multiply的更多相关文章

  1. tf.multiply()和tf.matmul()区别

    (1)tf.multiply是点乘,即Returns x * y element-wise. (2)tf.matmul是矩阵乘法,即Multiplies matrix a by matrix b, p ...

  2. tf.matmul函数和tf.multiply函数

    tf.matmul(a,b,transpose_a=False,transpose_b=False, adjoint_a=False, adjoint_b=False, a_is_sparse=Fal ...

  3. tf.matmul() 和tf.multiply() 的区别

    1.tf.multiply()两个矩阵中对应元素各自相乘 格式: tf.multiply(x, y, name=None) 参数: x: 一个类型为:half, float32, float64, u ...

  4. tf.matmul()和tf.multipy()的区别

    首先我们分析一下下面的代码: import tensorflow as tf import numpy as np a=tf.constant([[1., 2., 3.],[4., 5., 6.]]) ...

  5. 深度学习原理与框架-Tensorflow基本操作-mnist数据集的逻辑回归 1.tf.matmul(点乘操作) 2.tf.equal(对应位置是否相等) 3.tf.cast(将布尔类型转换为数值类型) 4.tf.argmax(返回最大值的索引) 5.tf.nn.softmax(计算softmax概率值) 6.tf.train.GradientDescentOptimizer(损失值梯度下降器)

    1. tf.matmul(X, w) # 进行点乘操作 参数说明:X,w都表示输入的数据, 2.tf.equal(x, y) # 比较两个数据对应位置的数是否相等,返回值为True,或者False 参 ...

  6. tf.matmul()报错expected scalar type Float but found Double

    tf.matmul(a,b)将矩阵a乘以矩阵b,生成a * b,这里的a,b要有相同的数据类型,否则会因为数据类型不匹配而出错. 如果出错,请看是前后分别是什么类型的,然后把数据类型进行转换.

  7. TF:TF下CNN实现mnist数据集预测 96%采用placeholder用法+2层C及其max_pool法+隐藏层dropout法+输出层softmax法+目标函数cross_entropy法+AdamOptimizer算法

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 ...

  8. TF:TF分类问题之MNIST手写50000数据集实现87.4%准确率识别:SGD法+softmax法+cross_entropy法—Jason niu

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 ...

  9. TF:TF之Tensorboard实践:将神经网络Tensorboard形式得到events.out.tfevents文件+dos内运行该文件本地服务器输出到网页可视化—Jason niu

    import tensorflow as tf import numpy as np def add_layer(inputs, in_size, out_size, n_layer, activat ...

随机推荐

  1. SpringMVC常用方法总结

    *) @RequestMapping(value="/xxx/{id}",method={RequestMethod.GET}) method 不写的话,默认GET.POST都支持 ...

  2. ECharts插件介绍(图表库)

    ECharts是一个非常好用的插件,用于进行 树状图,折线图,饼图,地图等等,系列视图的绘制.(详情看官网) 了解: AMD:模块化开发方式: 引入文件后:console.log(echarts) / ...

  3. C++返回栈上的数组(局部变量)问题探索

    char* teststr() { char s[] = "hello"; return s; } void main() { char* str = teststr(); ]; ...

  4. AOF — Redis 设计与实现

    w AOF — Redis 设计与实现http://redisbook.readthedocs.io/en/latest/internal/aof.html

  5. OKHttp3 简介与使用

    一.简介 Android系统提供了两种HTTP通信类:HttpURLConnection和HttpClient,前者对比后者十分难用. 网络请求进化:HttpURLConnection --- Apa ...

  6. python实现RESTful服务(基于flask)

    https://www.jianshu.com/p/6ac1cab17929 http://www.pythondoc.com/flask/quickstart.html 在java中调用python ...

  7. tensorflow 关于 矩阵 运算 + 符号得含义。 2维 数组 + 1纬数组, 就是每一行都 加一边 1纬数组。 呵呵

    小锋子Shawn(403568338)  13:51:23mnist.training.images?墨须(964489899)  13:51:27我的图片是100*100的,该怎么兼容.  小锋子S ...

  8. 监控java的进程启动情况(bat)

    最近有个项目需要检测某个软件崩溃重启的间隔和重启时间,百度了一下,按照自己的需求做了相应的修改 @echo off rem 定义需监控程序的进程名和程序路径,可根据需要进行修改 set AppName ...

  9. 剑指offer--day09

    1.1 题目:栈的压入.弹出序列:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列 ...

  10. Mac017--Jenkins 持续集成

    Jenkins 是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从繁杂的集成中解脱出来,专注于更为重要的业务逻辑实现上.同时 Jenkins 能实施监控集成中存在的错误,提供详细的日志文件和 ...