0

this post is linked to this post and this one.

I have tried the suggested function which works for small matrices. But I have a problem with big matrices.

I am trying to slice a (1088, 1920) into 32x32 blocks, but it doesn't work.

The values are ordered differently in the blocks than in the original matrix. Though the final dimensions on the outputed array are correct (2040, 32, 32) and the values of the first line are correct; the values of the second line of the first block is not the [1, 0:32] of the original array.

I don't really have a clue about where could the problem come from. Could it be a memory/buffer problem ?

Regards

  • It's hard to tell from your description what you want. While 1920 is 60*32, 1080 is not a multiple of 32. And I have not idea where the 2040 comes from. It's a good idea to test your ideas on small arrays that you (and we) can easily example. The linked answers demonstrate this. – hpaulj Mar 20 '21 at 23:33
  • the right dimension is1088 my bad, I ll correct – Thibaud LE GALL Mar 21 '21 at 00:01

1 Answers1

0

After investigation, there was an inversion between r and h. Therefore the right function is:

def split(array, nrows, ncols):
    """Split a matrix into sub-matrices."""

    r, h = array.shape
    return (array.reshape(r//nrows, nrows, -1, ncols)
                 .swapaxes(1, 2)
                 .reshape(-1, nrows, ncols))