How it works...
The last dimension of the matrix is responsible for channels. That's why we're manipulating it in the code.
To swap channels, we should get access to the corresponding slices of our matrix. But slices aren't copies of the original matrix, they're just different views of the same data. This means we can't perform swaps through temporary variables as we do with plain types. We need something more complicated here, and NumPy allows us to get not only a single slice, but a bunch of slices as new views of the data. To do so, we should enumerate indexes for all needed slices in the desired order, instead of just a single index.
When we use a single index, we get an access to the corresponding channel, and we can perform some algebraic operations on the slice.
The results should appear as follows: