I was wondering if there is a way to avoid for loop here:
I want to define a 4d matrix H(i,j,k,l), and each entry in the matrix is calculated through a complex function, say Do_H(i,j,k,l), depending on the index i, j, k, l.
Then I want to squeeze the 4d matrix to a 2d one, in the form below,
H(0,0,0,0) H (0,0,0,1) ... H(0,0,0,N)... H(0,0,1,0) ... H(0,0,N,N) H(0,1,0,0) H (0,1,0,1) ... H(0,1,0,N)... H(0,1,1,0) ... H(0,1,N,N) ... ... H(N,N,0,0) H (N,N,0,1) ... H(N,N,0,N)... H(N,N,1,0) ... H(N,N,N,N)
as a (N^2) by (N^2) size matrix. N is predefined.
UPDATE: Sorry if I confused you. There are two questions here:
- How to calculate each entry without going through the for loop?
- How to reshape the matrix?