When I use np.sum
, I encountered a parameter called keepdims
. After looking up the docs, I still cannot understand the meaning of keepdims
keepdims = true; In this case your dimensions of the array(Matrix) will be saved. That means the result you get is "broadcasted" correctly against the Array you are trying to implement the methods.
when you ignore it is just an ordinary array with no more dimensions.
import numpy as np
x = np.random.rand(4,3)
#Output for below statement: (3,)
print((np.sum(x, axis=0)).shape)
#Output for below statement: (1, 3)
print((np.sum(x, axis=0, keepdims=True)).shape)