Tensorflow学习笔记(2)

来源:互联网 发布:263网络通信 编辑:程序博客网 时间:2024/06/15 23:54
1、
tf.random_normal(shape,mean = 0.0,stddev = 1.0,dtype =tf.Float32, seed = None, name = None)
mean是平均值
stddev是标准正态分布的标准差(方差的开平方)

2、tf.placeholder()
tf.placeholder操作是占位符,即先定义有这么一种数据,其参数为数据的type和space
tf.placeholder(tf.float32,shape=(bachsize,cols))#其中bachsize表示数据类型的行数,cols表示列数。

3、tf.reduce_mean(tensor t)
tf.reduce_mean()返回的是tensor t中各个元素的平均值。
如:
# 'x' is [[1., 1.] 
#        [2., 2.]] 
tf.reduce_mean(x) ==> 1.5 
tf.reduce_mean(x, 0)==> [1.5,1.5]#列
tf.reduce_mean(x, 1)==> [1.,2.]#行

4、tf.reduce_max()
计算tensor中的各个元素的最大值,
reduce_max(t,1)是找出各行中最大值组成一个tensor
reduce_min(t,0)是找出各列中最大值组成一个tensor
同理,tf.reduce_min()则是计算tensor中各个元素的最小值


5、tf.reduce_all()
计算tensor中各个元素的逻辑和(and运算)
# 'x' is [[True, True] 
# [False, False]] 
tf.reduce_all(x) ==> False 
tf.reduce_all(x, 0)==> [False, False] 
tf.reduce_all(x, 1)==> [True, False]

6、tf.reduce_any()
计算tensor中各个元素的逻辑或(or运算)

7、tensorflow中的tensor包含三个特性:rank,shape,type
rank即tensor的维度,与C++中数组的维度类似,如23为0维,[23]是一维,[[1,2],[2,3]]是二维,[[[1,2],[2,3]],[[2,3],[3,4]]]是三维tensor
rank,shape和维度数的关系之间的关系
RankShapeDimension numberExample0[]0-DA 0-D tensor. A scalar.1[D0]1-DA 1-D tensor with shape [5].2[D0, D1]2-DA 2-D tensor with shape [3, 4].3[D0, D1, D2]3-DA 3-D tensor with shape [1, 4, 3].n[D0, D1, ... Dn-1]n-DA tensor with shape [D0, D1, ... Dn-1].
type就是tensor中数据的数据类型


0 0
原创粉丝点击