转自https://blog.csdn.net/lhanchao/article/details/51442181
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和维度数的关系之间的关系
Rank | Shape | Dimension number | Example |
---|---|---|---|
0 | [] | 0-D | A 0-D tensor. A scalar. |
1 | [D0] | 1-D | A 1-D tensor with shape [5]. |
2 | [D0, D1] | 2-D | A 2-D tensor with shape [3, 4]. |
3 | [D0, D1, D2] | 3-D | A 3-D tensor with shape [1, 4, 3]. |
n | [D0, D1, ... Dn-1] | n-D | A tensor with shape [D0, D1, ... Dn-1]. |
type就是tensor中数据的数据类型