It depends on the function you want to use for reduction. Usually the ufunc
add
or sum
is used to reduce axis. Keepdims=True
will ensure keeping the 4 axis intact after reduction. -
x = np.random.random((4, 3, 32, 32))
np.add.reduce(x,1,keepdims=True)
#(4,1,32,32)
x.sum(1, keepdims=True)
#(4,1,32,32)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…