【发布时间】:2016-06-10 06:09:21
【问题描述】:
在 ipython 中,我导入了 tensorflow as tf 和 numpy as np 并创建了一个 TensorFlow InteractiveSession。
当我使用 numpy 输入运行或初始化一些正态分布时,一切运行正常:
some_test = tf.constant(np.random.normal(loc=0.0, scale=1.0, size=(2, 2)))
session.run(some_test)
返回:
array([[-0.04152317, 0.19786302],
[-0.68232622, -0.23439092]])
正如预期的那样。
...但是当我使用 Tensorflow 正态分布函数时:
some_test = tf.constant(tf.random_normal([2, 2], mean=0.0, stddev=1.0, dtype=tf.float32))
session.run(some_test)
...它会引发类型错误:
(...)
TypeError: List of Tensors when single Tensor expected
我在这里缺少什么?
输出:
sess.run(tf.random_normal([2, 2], mean=0.0, stddev=1.0, dtype=tf.float32))
单独返回与 np.random.normal 生成的完全相同的内容 -> 形状为 (2, 2) 的矩阵,其值取自正态分布。
【问题讨论】:
标签: python numpy initialization tensorflow interactive-session