tensorflow约化平均值vs numpy平均值

tensorflow约化平均值vs numpy平均值,numpy,tensorflow,mean,Numpy,Tensorflow,Mean,据我所知,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

据我所知,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
猜猜为什么?

来自:

[1,2,3,4]的数据类型是int,而np.mean[1,2,3]默认情况下将其转换为浮点数组


请尝试tf.constantnp.arange3.0。

谢谢您的回复。我无法理解为什么数据类型很重要。你认为tensorflow会把4.625轮到4轮吗?是的,整数除法和取多个整数的平均值是先对整数求和,然后在默认情况下对这些整数的总数进行俯冲,例如27//10==2,尽管2.7似乎更接近3。
If the argument dtype is not specified, then the type is inferred from the type of value.