I'm reading the book Deep Learning from scratch. .. ..
The following formula that uses the numerical calculation library NumPy to specify the axis for a matrix and perform aggregation.
> m = np.array(...)
> m.sum(axis=0)
I couldn't keep up with the processing of the brain to see how this works, so I made a picture.
> m = np.array([[2,1],[3,4]])
axis=0
> m.sum(axis=0)
array([5, 5])
axis=1
> m.sum(axis=1)
array([3, 7])
m = np.array([[[7,8],[2,1]],[[6,5],[3,4]]])
axis=0
> m.sum(axis=0)
array([[13, 13]
[ 5, 5]])
axis=1
> m.sum(axis=1)
array([[9, 9]
[9, 9]])
axis=2
> m.sum(axis=2)
array([[15, 3]
[11, 7]])
Recommended Posts