tensorflow的一些函数

1.tf.constant(value,dtype=None,shape=None,name='Const')

注意这个函数创造的是一个常数tensor,而不是一个具体的常数

value:即可以是list,也可以是value

dtype:对应生成的tensor里的元素的类型

# Constant 1-D Tensor populated with value list.
 tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]              注意这种直接加入list的情况

 # Constant 2-D tensor populated with scalar value -1.
 tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.]
                                              [-1. -1. -1.]]

对于value给tensor,并不是不能shape形状,如果shape出来value中的元素不够用时,就以最后一个元素重复出现填充至满足形状。

以下实例:

>>> sess = tf.InteractiveSession()

>>> a = tf.constant([1,2,3],shape = [6])
>>> b = tf.constant([1,2,3],shape = [3,2])
>>> c = tf.constant([1,2,3],shape = [2,3])

>>> print sess.run(a)
[1 2 3 3 3 3]
>>> print sess.run(b)
[[1 2]
 [3 3]
 [3 3]]
>>> print sess.run(c)
[[1 2 3]
 [3 3 3]]

 

 2.tf.truncated_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None)

这个函数是从截断的正态分布产生随机数

mean:均值

stddev:标准差

posted @ 2017-03-10 12:12  有梦就要去实现他  阅读(435)  评论(0编辑  收藏  举报