tensorflow中的一些操作和numpy中的很像,下面列出几个比较常见的操作

import tensorflow as tf

#定义三行四列的零矩阵
tf.zeros([3,4])
#定义两行三列的全1矩阵
tf.ones([2,3])
#定义常量
tensor = tf.constant([1,2,3,4,5,6,7])
#定义两行三列全为-1的矩阵
tensor = tf.constant(-1.0.shape=[2,3])
#[10 11 12]
tf.linspace(10.0,12.0,3,name="linespace") tf.range(start,end,delta)
#构造两行三列的均值为mean,方差为stddev的符合正态分布的矩阵
norm = tf.random_normal([2,3],mean=-1,stddev=4)
#洗牌操作
c = tf.constant([[1,2],[3,4],[5,6]])
shuff = tf.random_shuffle(c)

sess = tf.Session()
 print(sess.run(norm))
 print(sess.run(shuff))

#赋个初始值
state = tf.Variable(0)
#初始值加1
new_value = tf.add(state, tf.constant(1))
#更新
update = tf.assign(state, new_value)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(state))
for _ in range(3):
sess.run(update)
print(sess.run(state))
#numpy向tensorflow转换
import numpy as np
a = np.zeros((3,3))
ta = tf.convert_to_tensor(a)
with tf.Session() as sess:
print(sess.run(ta))
#tensorflow中的placeholder
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:[7.],input2:[2.]}))

最新文章

  1. Android raw to bmp
  2. AO安装需要Microsoft Visual Studio 2013?
  3. internet选项菜单灰色
  4. FineUI第十二天---锚点布局
  5. storyboard有多个Segue的传递
  6. hibernate中many-to-one关联时出现ObjectNotFoundException异常
  7. rabbitmq之消息转储vm_memory_high_watermark_paging
  8. 第九天 内容提供者 ContentResolver
  9. Lazarus IDE的几个小技术
  10. [网络]远程访问局域网svn服务器[转]
  11. 《web全栈工程师的自我修养》阅读笔记
  12. 2 MySQL安装
  13. 关于iOS常用的26中公共方法,可copy的代码
  14. LindDotNetCore~添加路由前缀
  15. Python和C++的混合编程(使用Boost编写Python的扩展包)
  16. springboot项目简单启动脚本
  17. MySQL Network--Localhost与127.0.0.1的差异
  18. Docker的概述
  19. 自然语言处理--LDA主题聚类模型
  20. Qt5中运行后台网络读取线程与主UI线程互交

热门文章

  1. 浅谈Android的资源编译过程
  2. Cloud Computing——Everything as a Service
  3. Oracle --45 个非常有用的 Oracle 查询语句
  4. ArrayList类源码浅析(二)
  5. SpringBoot 整合Shiro 一指禅
  6. 利用Eclipse CDT 阅读C/C++代码
  7. hdu 4511 (AC自动机)
  8. Python 笔试集(2):你不知道的 Python 整数
  9. Unity UI —Text
  10. Debian或者Ubuntu中安装secureCRT/secureFX