A short tutorial on array reshape and rotation

by Marco Pascucci

Please consider the more readable HTML version of this document

Array reshaping and rotation can be confusing. in this short guide I will try to visualize what happens when using the numpy functions corresponding to these operations.

Reshape

An array can be reshaped only if the product of the dimensions is the same. for example:

are all valid shapes

What reshape does is just "cut the array data according to the values ijk".

3D volume rotation

Take your time to learn to visualize 3D arrays as volumes.

The following volume has $i$ pages, each page has $j$ rows and $k$ columns

This array has 3 dimensions: $i,j,k$ which can be rearranged in $3!=6$ permutations

In 3D it can be seen as a parallelepiped, with 6 faces, which can be rotated so that we see a particular face in front of us.

Each such rotation corresponds to a particular permutation of $i,j,k$

The elementary operation that change the permutation of the index is an "axis swap" (e.g. ijk -> kji where i and k have been swapped).

A ciclical shift of the axes corresponds to two successive swapping on two orthogonal faces

Functions which apply volume rotations

A practical exercice

with numbers