Reshape 4d numpy array to 2d array while preserving array locations

前端 未结 1 353
春和景丽
春和景丽 2021-01-18 00:33

I have a 4 dimensional numpy array of shape (N, N, Q, Q). So given a row and column index (i, j), mat[i,j] is a QxQ matri

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 01:11

    Nevermind, I figured it out. np.swapaxes(1, 2) was the missing piece I needed.

    The answer is just to do mat.swapaxes(1, 2).reshape(N*Q, N*Q).

    Feel foolish for posting without attempting to figure it out myself for too long, but I'll leave it up so others can benefit from it.

    0 讨论(0)
提交回复
热议问题