据我理解,tensorflow reduce_mean和numpy mean应该返回相同的值,但是下面的示例返回不同的值:
import numpy as np
import tensorflow as tf
t_1 = tf.constant([1,3,4,5])
t_2 = tf.constant([7,8,9,0])
list_t = [t_1, t_2]
reduced_t_list = tf.reduce_mean(list_t)
sess= tf.Session()
print(sess.run(reduced_t_list))
print(np.mean([1,3,4,5,7,8,9,0]))
output:
4
4.625有猜到原因吗?
发布于 2017-10-07 22:22:22
来自 docs
If the argument dtype is not specified, then the type is inferred from the type of value.dtype of [1, 2, 3, 4]是int,而np.mean([1, 2, 3])默认将其转换为float的数组。
试试tf.constant(np.arange(3.0))。
https://stackoverflow.com/questions/46625632
复制相似问题