Tensorflow | Random |常用函数介绍
2017-03-05 17:46
441 查看
根据官网的帮助文档,介绍Random类型的函数,方便自己学习和查看。若是有幸帮到别的朋友,深感荣幸。
rf.random_normal
产生正态随机分布
格式:tf.random_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None)
shape定义维度,mean定义均值,stddev定义方差,dtype定义类型,seed定义种子,name定义名称
例子:
结果:
[[ -7.80873823 -10.97159195 -11.99345589]
[ 1.79066849 -4.10513306 4.37571764]]
tf.truncated_normal
产生标准正态分布
格式:tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
shape定义维度,mean定义均值,stddev定义方差,dtype定义类型,seed定义种子,name定义名称
例子:
结果:
[[ 1.89490759 -1.03072059 0.2172989 ]
[-0.29377019 -0.38990787 -1.09539473]]
tf.random_uniform
产生均匀分布
格式:tf.random_uniform(shape, minval=0.0, maxval=1.0, dtype=tf.float32, seed=None, name=None)
shape定义维度,minval区间最小值,maxval区间最大值,dtype定义类型,seed定义种子,name定义名称
例子:
结果:
[[ 2.73986316 1.50323987 1.64366412]
[ 1.12579513 1.52106118 1.29330397]]
-tf.random_shuffle
随机的交换位置
格式:tf.random_shuffle(value, seed=None, name=None)
value是一个给定的张量,seed定义的种子,name定义名称
例子:
结果:
[[1 2]
[5 6]
[3 4]]
tf.set_random_seed
设置种子
格式:tf.set_random_seed(seed)
seed是给定的种子
例子:
结果:
[ 0.59309709]
[ 0.32048994]
每次运行结果都不一致。要一致还是在定义张量的内部来设置。
rf.random_normal
产生正态随机分布
格式:tf.random_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None)
shape定义维度,mean定义均值,stddev定义方差,dtype定义类型,seed定义种子,name定义名称
例子:
import tensorflow as tf # Create a tensor of shape [2, 3] consisting of random normal values, with mean # -1 and standard deviation 4. norm = tf.random_normal(shape=[2, 3], mean=-1, stddev=4) with tf.Session() as sess: print (sess.run(norm))
结果:
[[ -7.80873823 -10.97159195 -11.99345589]
[ 1.79066849 -4.10513306 4.37571764]]
tf.truncated_normal
产生标准正态分布
格式:tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
shape定义维度,mean定义均值,stddev定义方差,dtype定义类型,seed定义种子,name定义名称
例子:
import tensorflow as tf # Create a tensor of shape [2, 3] consisting of random normal values, with mean # 0 and standard deviation 1. norm = tf.truncated_normal(shape=[2,3],mean=0,stddev=1) with tf.Session() as sess: print (sess.run(norm))
结果:
[[ 1.89490759 -1.03072059 0.2172989 ]
[-0.29377019 -0.38990787 -1.09539473]]
tf.random_uniform
产生均匀分布
格式:tf.random_uniform(shape, minval=0.0, maxval=1.0, dtype=tf.float32, seed=None, name=None)
shape定义维度,minval区间最小值,maxval区间最大值,dtype定义类型,seed定义种子,name定义名称
例子:
import tensorflow as tf # Create a tensor of shape [2, 3] consisting of random uniform values, with minval=1 # and maxval =3. norm = tf.random_uniform(shape=[2,3],minval=1,maxval=3) with tf.Session() as sess: print (sess.run(norm))
结果:
[[ 2.73986316 1.50323987 1.64366412]
[ 1.12579513 1.52106118 1.29330397]]
-tf.random_shuffle
随机的交换位置
格式:tf.random_shuffle(value, seed=None, name=None)
value是一个给定的张量,seed定义的种子,name定义名称
例子:
import tensorflow as tf c = tf.constant([[1,2],[3,4],[5,6]]) shuff = tf.random_shuffle(value=c,seed=1,name="shuff") with tf.Session() as sess: print (sess.run(shuff))
结果:
[[1 2]
[5 6]
[3 4]]
tf.set_random_seed
设置种子
格式:tf.set_random_seed(seed)
seed是给定的种子
例子:
import tensorflow as tf tf.set_random_seed(1234) a = tf.random_uniform([1]) b = tf.random_normal([1]) with tf.Session() as sess: print (sess.run(a)) print (sess.run(b))
结果:
[ 0.59309709]
[ 0.32048994]
每次运行结果都不一致。要一致还是在定义张量的内部来设置。
相关文章推荐
- Tensorflow | Sequences | 常用函数介绍
- tensorflow的一些代码分析(四) tensorflow常用函数介绍
- tensorflow常用函数介绍
- tensorflow常用函数介绍
- Tensorflow | Constants |常用函数介绍
- OCI 常用函数介绍[摘抄]
- EXCEL常用函数介绍
- MFC中常用类,宏,函数介绍
- MFC中常用类,宏,函数介绍
- Asp.Net常用函数介绍
- DOM常用功能及常用函数介绍
- 第二十课:常用函数介绍--字符串操作函数
- ORACLE常用数值函数、转换函数、字符串函数介绍
- ORACLE常用数值函数、转换函数、字符串函数介绍
- sybase常用函数介绍
- MFC中常用类、宏、函数介绍
- STL知识点(常用算法函数介绍 、容器、类属算法、迭代器、函数对象、适配器、分配器
- MFC中常用类,宏,函数介绍
- ASP常用函数介绍
- SD--相关的函数列表的介绍系列篇和常用的BAPI(1)