12
在numpy.sum()中有一個名爲「keepdims」的參數。它有什麼作用?在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.
...
你有沒有試過這個例子,有沒有這個參數?在交互式會話中測試應該很容易。 – hpaulj
如果您知道沒有它的「總和」,這個參數是最有意義的。您是否熟悉結果的形狀取決於輸入數組以及軸的選擇? – hpaulj