博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tensorflow中张量、常量、变量、占位符
阅读量:7113 次
发布时间:2019-06-28

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

1.tensor

在tensorflow中,数据是被封装在tensor对象中的。tensor是张量的意思,即包含从0到任意维度的张量。常数是0维度的张量,向量是1维度的张量,矩阵是二维度的张量,以及还有多维度的张量。

 
1 # tensor1 是一个0维的 int32 tensor2 tensor1 = tf.constant(1234) 3 # tensor2 是一个1维的 int32 tensor4 tensor2 = tf.constant([123,456,789]) 5  # tensor3 是一个二维的 int32 tensor6 tensor3 = tf.constant([ [123,456,789], [222,333,444] ])
View Code
 

 

 

2.tf.constant

constant函数提供在tensorflow中定义常量(不可更改的张量)的方法

如:

tensor_constant = tf.constant([1,2,3,4)

3.tf.Variable

tensorflow中的变量是通过Variable类来实现的。tensorflow中需要定义为变量的包括训练过程中的输入数据,输出数据,以及控制从输入到输出的学习机制,即网络参数。输入输出数据在tf中是用placeholder占位符来定义的,网络参数是用tf.Variable来定义的。

4.tf.placeholder

用于声明一个张量的数据格式,告诉系统这里会有一个这种格式的张量,但是还没有传入具体的值。

如:

X = tf.placeholder("float", shape=[None, 100])

上面声明了一个张量X,数据类型是float,100列,行数不确定。

5.tf.Session

以上部分都是搭建一个计算图的代码,在tf中,先搭建好计算图,然后再启动session,运行定义好的图。

1 import tensorflow as tf2  3 x = tf.placeholder("string")4 with tf.Session() as sess:5     output = sess.run(x, feed_dict={x : "run the map"})6     print(output)
View Code

 

转载于:https://www.cnblogs.com/xinmomoyan/p/10170958.html

你可能感兴趣的文章
Tap-Ahead:让移动搜索更加便捷的解决之道
查看>>
Windows Server2016 Hyper-v Cluster部署
查看>>
juniper路由器配置
查看>>
jQuery一点一滴系列教程(第三点)
查看>>
ARP解决方法/工具 真假ARP防范区别方法 ARP终极解决方案
查看>>
系统数据权限的实现方案
查看>>
华为vlan划分,单臂路由以及静态路由
查看>>
UCD 2010百度工作坊
查看>>
ssh2免密码登录
查看>>
4_move_find_into_model
查看>>
MySQL · 捉虫动态 · UK 包含 NULL 值备库延迟分析
查看>>
windows server 2012 standard Evaluation 安装试用
查看>>
windows server 2008中配置TCP/IP
查看>>
网管必读:交换机技术简介及应用分析
查看>>
.NET多线程编程(9)——Thread类
查看>>
HP DL380G6上安装配置Vmware_ESXI4.1
查看>>
单IP无TMG拓扑Lync Server 2013:活动目录
查看>>
3.VMware vsphere 5.0新体验-安装VMware Center
查看>>
趣题: 一道面试题的解法
查看>>
Java Scoket之java.io.EOFException解决方案
查看>>