import tensorflow as tf
import numpy as np
原型:np.random.randint(low, high=None, size=None, dtype=‘l’)
'''
当只有low时候,返回的值范围是[0,low).有low和high时候,返回值范围是[low,high).
'''
t1 = np.random.randint(2,size=10)
print(t1)
t2 = np.random.randint(low=1,high=3,size=10)
print(t2)
原型:np.random.rand(d0, d1, …, dn),其中di表示维数
'''
返回范围为[0,1)均匀分布
'''
t3 = np.random.rand(3, 2)
print(t3)
原型:tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=dtypes.float32, seed=None, name=None)
shape: 输出张量的形状,必选
mean: 正态分布的均值,默认为0
stddev: 正态分布的标准差,默认为1.0
dtype: 输出的类型,默认为tf.float32
seed: 随机数种子,是一个整数,当设置之后,每次生成的随机数都一样
name: 操作的名称
'''
根据shape返回一个张量,其中值服从均值为0,方差为1的正态分布
'''
t4 = tf.random_normal((3, 2))
print(t4)
with tf.Session() as sess:
init =tf.global_variables_initializer()
print(sess.run(t4))
原型:tf.random_uniform(shape, minval=0, maxval=None, dtype=dtypes.float32, seed=None, name=None)
'''
从均匀分布中随机取值,范围为[minval,maxval)
'''
t5 = tf.random_uniform((3, 2),minval=1,maxval=3)
print(t5)
with tf.Session() as sess:
init =tf.global_variables_initializer()
print(sess.run(t5))