在 ipython 中我导入了tensorflow as tf
and numpy as np
并创建了一个 TensorFlowInteractiveSession
。
当我使用 numpy 输入运行或初始化一些正态分布时,一切运行正常:
some_test = tf.constant(np.random.normal(loc=0.0, scale=1.0, size=(2, 2)))
session.run(some_test)
Returns:
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)
值取自正态分布。