問題文
A developer needs the mean of a tensor of shape (8, 100) along the feature axis, and wants the result to keep a trailing dimension of size 1 so that it can be subtracted from the original tensor without reshaping. Which call does that?
選択肢
- x.mean(dim=1, keepdim=True), which reduces the second axis but leaves it in place with size 1.
- x.mean(1).reshape(8, 100), which restores the shape.
- x.mean(dim=1), because the reduction functions preserve the reduced axis with size 1 by default and only drop it when asked to.
- x.mean(axis=1, squeeze=False), which keeps the reduced axis.