据我所知,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
任何猜测为什么?
答案 0 :(得分:1)
If the argument dtype is not specified, then the type is inferred from the type of value.
dtype
的{{1}}为[1, 2, 3, 4]
,而int
默认会将其投放到np.mean([1, 2, 3])
的数组中。
尝试float
。