首先,TensorFlow官网给出的解释:
tf.random_normal(
shape,
mean=0.0,
stddev=1.0,
dtype=tf.float32,
seed=None,
name=None
)
shape代表形状,也就是1纬的还是2纬的还是n纬的数组。
下面看图说话:
import tensorflow as tf
res = tf.random_uniform([1], -1, 1)
with tf.Session() as sess:
print(sess.run(res))
#结果为:[0.8457055]
import tensorflow as tf
res = tf.random_uniform([2], -1, 1)
with tf.Session() as sess:
print(sess.run(res))
#结果为:[-0.20672345 0.6750064 ]
import tensorflow as tf
res = tf.random_uniform((4, 4), -1, 1)
with tf.Session() as sess:
print(sess.run(res))
#结果为:
[[ 0.61043835 -0.35983467 -0.02590227 0.6653023 ]
[ 0.4215083 0.6378925 -0.5907881 0.94997907]
[ 0.02292204 -0.7329526 0.03539038 -0.63158727]
[ 0.15353537 -0.21372676 -0.5452025 -0.44808888]]
tf.random_uniform((4, 4), minval=low,maxval=high,dtype=tf.float32)))返回4*4的矩阵,产生于low和high之间,产生的值是均匀分布的。