Suppose I have a four-dimensional array and I would like to flatten the first two indices and the last two indices. For example, with a 2x2x2x2 array, this would yield a (2×2)x(2×2)=4×4 array. How can I do this?
In other words, I want to reindex an array in the fashion of
A_new[2*n+m,2*q+p] = A_old[m,n,p,q]
where the first two indices have been consolidated into one large index and so have the last two indices. To my knowledge, reshape
doesn’t allow this level of control into the reindexing. How can I achieve it?