为什么第 0 层意味着 reduce_mean 给出错误的平均值?

问题描述 投票:0回答:2

我这里有第三层阵列

t = tf.constant([[[1., 1., 1.], [2., 2., 2.]], [[3., 3., 3.], [4., 4., 4.]]])
tf.reduce_mean(t,0)

我认为第 0 层均值是 1.5 和 3.5。但是,它给了我 2 和 3。有人可以帮助解释这里发生的事情吗?

<tf.Tensor: id=8966, shape=(2, 3), dtype=float32, numpy=
array([[2., 2., 2.],
       [3., 3., 3.]], dtype=float32)>

另外,我不明白的是为什么不

t = tf.constant([[[1., 1., 1.], [2., 2., 2.]], [[3., 3., 3.], [4., 4., 4.]]])
tf.reduce_mean(t,2)

给出答案

[[[1.],[2.]],
 [[3.],[4.]]]

?它给出了一个答案

<tf.Tensor: id=9014, shape=(2, 2), dtype=float32, numpy=
array([[1., 2.],
       [3., 4.]], dtype=float32)>

第2层[]去哪了?

层的哪一部分我没有理解正确?

arrays tensorflow layer tensor
2个回答
1
投票

这是对

tf.reduce_mean
如何作用于
axis=0
的描述。

你有一个

(2,2,3)
数组。
tf.reduce_mean(t, 0)
通过在
(2,3)
上压缩数组(通过取平均值)生成一个
axis=0
数组,如图所示。您可以将其可视化为任何其他维度。

每当您在轴上执行

reduction
操作时,该轴就会消失(实际上变成
1
)。如果你想保持那个尺寸,只需设置
tf.reduce_mean(t, 0, keepdims=True)
.


0
投票

谢谢!帮助很大。在 pandas 中,axis=0 表示行。这是“专栏”

© www.soinside.com 2019 - 2024. All rights reserved.