From the question you linked to, it's just a small change in the code:
def crop_center(img,cropx,cropy):
y,x,c = img.shape
startx = x//2 - cropx//2
starty = y//2 - cropy//2
return img[starty:starty+cropy, startx:startx+cropx, :]
All that was added was another :
to the end of the last line, and an (unused) c
to the shape unpacking.
>>> img
array([[[ 18, 1, 17],
[ 1, 13, 3],
[ 2, 17, 2],
[ 5, 9, 3],
[ 0, 6, 0]],
[[ 1, 4, 11],
[ 7, 9, 24],
[ 5, 1, 5],
[ 7, 3, 0],
[116, 1, 55]],
[[ 1, 4, 0],
[ 1, 1, 3],
[ 2, 11, 4],
[ 20, 3, 33],
[ 2, 7, 10]],
[[ 3, 3, 6],
[ 47, 5, 3],
[ 4, 0, 10],
[ 2, 1, 35],
[ 6, 0, 1]],
[[ 2, 9, 0],
[ 17, 13, 4],
[ 3, 0, 1],
[ 16, 1, 3],
[ 19, 4, 0]],
[[ 8, 19, 3],
[ 9, 16, 7],
[ 0, 12, 2],
[ 4, 68, 10],
[ 4, 11, 1]],
[[ 0, 1, 14],
[ 0, 0, 4],
[ 13, 1, 4],
[ 11, 17, 5],
[ 7, 0, 0]]])
>>> crop_center(img,3,3)
array([[[ 1, 1, 3],
[ 2, 11, 4],
[20, 3, 33]],
[[47, 5, 3],
[ 4, 0, 10],
[ 2, 1, 35]],
[[17, 13, 4],
[ 3, 0, 1],
[16, 1, 3]]])