【发布时间】:2018-10-02 09:55:01
【问题描述】:
我正在使用带有 numpy random 函数的 Tensorflow,但输出是相同的值。如何生成不同的值?你可能会推荐使用原生 tf 随机函数,但我需要使用 numpy 随机函数。
import tensorflow as tf
import random
def get_rand():
return random.randint(0,5)
a = get_rand()
tfprint = tf.Print(a, [a])
for i in range(10):
print(print(get_rand()))
with tf.Session() as sess:
for i in range(10):
sess.run(tfprint)
【问题讨论】:
-
我刚刚运行了你的代码,它打印了 10 个不同的随机数。有什么问题?
-
Numpy 部分会生成随机数,但 Tensorflow 部分不会。
标签: numpy tensorflow random