2

Suppose I have a numpy array of size 4x4:

      1 1 1 1
A =   1 1 1 1
      1 1 1 1
      1 1 1 1

I want to reshape the above matrix into blocks of 2x2 shaped matrices such that the entries in this new matrix are the sums of the four quadrants of the 4x4 matrix.

B = 4 4
    4 4

I am wondering if there is a simple way to do this in NumPy. numpy.reshape() does not allow for the data to be aggregated, so I am wondering if this would be something I need to do in an iteration.

Divakar
  • 218,885
  • 19
  • 262
  • 358
GrayLiterature
  • 381
  • 2
  • 13

0 Answers0