【发布时间】:2017-01-19 08:55:45
【问题描述】:
在numpy.sum() 中有一个名为keepdims 的参数。它有什么作用?
正如您在文档中看到的: http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html
numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)[source]
Sum of array elements over a given axis.
Parameters:
...
keepdims : bool, optional
If this is set to True, the axes which are reduced are left in the result as
dimensions with size one. With this option, the result will broadcast
correctly against the input array.
...
【问题讨论】:
-
你试过这些例子,有没有这个参数?它应该很容易在交互式会话中进行测试。
-
如果您知道
sum没有它会做什么,这个参数最有意义。您是否熟悉结果的形状如何取决于输入数组和轴的选择?