Axis specification in NumPy

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.

When ndim = 2

> m = np.array([[2,1],[3,4]])

axis=0

> m.sum(axis=0)
array([5, 5])

1.png

axis=1

> m.sum(axis=1)
array([3, 7])

1.png

When ndim = 3

m = np.array([[[7,8],[2,1]],[[6,5],[3,4]]])

axis=0

> m.sum(axis=0)
array([[13, 13]
       [ 5,  5]])

1.png

axis=1

> m.sum(axis=1)
array([[9, 9]
       [9, 9]])

1.png

axis=2

> m.sum(axis=2)
array([[15, 3]
       [11, 7]])

1.png

Recommended Posts

Axis specification in NumPy
NumPy axis
where in numpy
Install numpy in Visual Studio 2019
Imitated Python's Numpy in C #
Matrix multiplication in python numpy
Accelerate Zhang-Suen algorithm in Numpy
Put python, numpy, opencv3 in ubuntu14
Self-organizing map in Python NumPy version
[Numpy] Call savetxt () in append mode
Invert numpy Boolean array in tilde
Jupyter, numpy, matplotlib notes used in reports
A memo explaining the axis specification of axis
Axis option specification summary of Python "numpy.sum (...)"