I'm trying to using numpy.lib.stride_tricks.as_strided to iterate over non-overlapping blocks of an array, but I'm having trouble finding documentation of the parameters, so I've only been able to get overlapping blocks.
For example, I have a 4x5 array which I'd like to get 4 2x2 blocks from. I'm fine with the extra cells on the right and bottom edge being excluded.
So far, my code is:
import sys
import numpy as np
a = np.array([
[1,2,3,4,5],
[6,7,8,9,10],
[11,12,13,14,15],
[16,17,18,19,20],
])
sz = a.itemsize
h,w = a.shape
bh,bw = 2,2
shape = (h/bh, w/bw, bh, bw)
strides = (w*sz, sz, w*sz, sz)
blocks = np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)
print blocks[0][0]
assert blocks[0][0].tolist() == [[1, 2], [6,7]]
print blocks[0][1]
assert blocks[0][1].tolist() == [[3,4], [8,9]]
print blocks[1][0]
assert blocks[1][0].tolist() == [[11, 12], [16, 17]]
The shape of the resulting blocks array seems to be correct, but the last two asserts fail, presumably because my shape or strides parameters are incorrect. What values for these should I set to get non-overlapping blocks?