May-11-2017, 10:33 AM
(May-11-2017, 09:12 AM)zivoni Wrote: It seems that you can useThank you !!! This works perfectly for me..sum()
method with axis parameter.
In [1]: import numpy as np In [2]: a = np.array([[[1,2], [3,4]], [[10, 20], [30, 40]]]) In [3]: a Out[3]: array([[[ 1, 2], [ 3, 4]], [[10, 20], [30, 40]]]) In [4]: a.sum(axis=0) Out[4]: array([[11, 22], [33, 44]])As you can see, result has dimensionality reduced to (2, 2), if you want result with shape (2, 2, 1), you need to reshape it or add new dimension:
In [5]: a.sum(axis=0)[..., None] Out[5]: array([[[11], [22]], [[33], [44]]])