# Tensorflow | Random |常用函数介绍

• rf.random_normal

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))```

• tf.truncated_normal 产生标准正态分布

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))```

• tf.random_uniform 产生均匀分布

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))```

-tf.random_shuffle

```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))```

• tf.set_random_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))```

176 篇文章40 人订阅

0 条评论