I have a 2n x 2m numpy array. I would like to form a n x m array by selecting randomly one element in 2 x 2 non-overlapping sub-arrays that partition my initial array. What would be the best way to do so? Is there a way to avoid two for loops (one along each dimension)?
For example, if my array is
1 2 3 4
5 6 7 8
9 0 1 2
8 5 7 0
then, there are four 2 x 2 sub-arrays that partition it:
1 2 3 4
5 6 7 8
9 0 1 2
8 5 7 0
and I would like to pick up randomly one element in each of them to form new arrays, such as
5 3 , 6 8 , 2 3
9 2 9 1 0 0 .
Thank you for your time.