I've seen this: Slice 2d array into smaller 2d arrays
However, I have images that cannot be evenly split into some N by N blocks. Ideally, I'd like for the following behavior to occur:
>>> import numpy as np
>>> a = np.arange(70*85).reshape([70,85])
>>> arrlist = split_2d(a, [16, 16])
>>> dd = dict()
>>> for arr in arrlist:
... dd[arr.shape] = dd.get(arr.shape, 0) + 1
>>> print(dd)
{(16, 16): 16, (10, 16): 4, (16, 5): 4, (10, 5): 1}
Which reflects splitting a (70x85) array into the following:
(16x16) (16x16) (16x16) (16x16) (10x16)
(16x16) (16x16) (16x16) (16x16) (10x16)
(16x16) (16x16) (16x16) (16x16) (10x16)
(16x16) (16x16) (16x16) (16x16) (10x16)
(16x16) (16x16) (16x16) (16x16) (10x16)
(16x5) (16x5) (16x5) (16x5) (10x5)
The return value can either be a list of 2D arrays, or a 2D array of 2D arrays.