博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tensorflow矩阵的运算
阅读量:3907 次
发布时间:2019-05-23

本文共 1035 字,大约阅读时间需要 3 分钟。

一个实例(矩阵乘法matmul)

import osos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #CPU的分配问题import numpy"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""import tensorflow as tfmatrix1 = tf.constant([[3, 3]])matrix2 = tf.constant([[2],                       [2]])product = tf.matmul(matrix1, matrix2)  # matrix multiply np.dot(m1, m2)# method 1sess = tf.compat.v1.Session()result = sess.run(product)print(result)sess.close()# method 2with tf.compat.v1.Session() as sess:    result2 = sess.run(product)    print(result2)

矩阵乘法(multiply)

#初始化cup的分配import osos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""import tensorflow as tfinput1 = tf.compat.v1.placeholder(tf.float32)input2 = tf.compat.v1.placeholder(tf.float32)ouput = tf.multiply(input1, input2)with tf.compat.v1.Session() as sess:    print(sess.run(ouput, feed_dict={
input1: [7.], input2: [2.]}))

matmul和multiply区别参考文章:

转载地址:http://tfkrn.baihongyu.com/

你可能感兴趣的文章
客户的一个紧急bug,我用了两种方式进行 C# 反编译修改源码
查看>>
.NET5都来了,你还不知道怎么部署到linux?最全部署方案,总有一款适合你
查看>>
我画着图,FluentAPI 她自己就生成了
查看>>
BenchmarkDotNet v0.12x新增功能
查看>>
使用 .NET 5 体验大数据和机器学习
查看>>
C# 中的数字分隔符 _
查看>>
持续交付一:从开发到上线的环境
查看>>
使用 docker 构建分布式调用链跟踪框架skywalking
查看>>
深度探秘.NET 5.0
查看>>
Github Actions 中 Service Container 的使用
查看>>
天际数见数据质量巡检架构优化
查看>>
别在.NET死忠粉面前黑.NET5,它未来可期!
查看>>
Winform 进度条弹窗和任务控制
查看>>
部署Dotnet Core应用到Kubernetes(二)
查看>>
持续交付二:为什么需要多个环境
查看>>
简单理解线程同步上下文
查看>>
购票啦 | 2020中国.NET开发者峰会启动
查看>>
FreeSql接入CAP的实践
查看>>
浅析 EF Core 5 中的 DbContextFactory
查看>>
听说容器正在吃掉整个软件世界?
查看>>