Your 3 arrays:
In [46]: x=np.arange(1,10).reshape(3,3)
In [48]: y=np.arange(10,19).reshape(3,3)
In [49]: z=np.arange(19,28).reshape(3,3)
combined into one:
In [50]: xyz=np.stack((x,y,z))
In [51]: xyz
Out[51]:
array([[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]],
[[10, 11, 12],
[13, 14, 15],
[16, 17, 18]],
[[19, 20, 21],
[22, 23, 24],
[25, 26, 27]]])
Your a1 (2,2) array:
In [55]: xyz[0,:2,:2]
Out[55]:
array([[1, 2],
[4, 5]])
and all 3:
In [56]: xyz[:,:2,:2]
Out[56]:
array([[[ 1, 2],
[ 4, 5]],
[[10, 11],
[13, 14]],
[[19, 20],
[22, 23]]])
and rearrange them into the desired (4,3):
In [57]: xyz[:,:2,:2].transpose(1,2,0)
Out[57]:
array([[[ 1, 10, 19],
[ 2, 11, 20]],
[[ 4, 13, 22],
[ 5, 14, 23]]])
In [58]: xyz[:,:2,:2].transpose(1,2,0).reshape(4,3)
Out[58]:
array([[ 1, 10, 19],
[ 2, 11, 20],
[ 4, 13, 22],
[ 5, 14, 23]])
similarly for the other windows:
In [59]: xyz[:,1:3,:2].transpose(1,2,0).reshape(4,3)
Out[59]:
array([[ 4, 13, 22],
[ 5, 14, 23],
[ 7, 16, 25],
[ 8, 17, 26]])
In [60]: xyz[:,0:2,1:3].transpose(1,2,0).reshape(4,3)
Out[60]:
array([[ 2, 11, 20],
[ 3, 12, 21],
[ 5, 14, 23],
[ 6, 15, 24]])
In [61]: xyz[:,1:3,1:3].transpose(1,2,0).reshape(4,3)
Out[61]:
array([[ 5, 14, 23],
[ 6, 15, 24],
[ 8, 17, 26],
[ 9, 18, 27]])
We could also the view_as_windows as @Divakar suggested (or as_strided), but conceptually that's trickier.
====
I can skip the transpose if I stack differently:
In [65]: xyz=np.stack((x,y,z), axis=2)
In [66]: xyz
Out[66]:
array([[[ 1, 10, 19],
[ 2, 11, 20],
[ 3, 12, 21]],
[[ 4, 13, 22],
[ 5, 14, 23],
[ 6, 15, 24]],
[[ 7, 16, 25],
[ 8, 17, 26],
[ 9, 18, 27]]])
In [68]: xyz[:2,:2].reshape(4,3)
Out[68]:
array([[ 1, 10, 19],
[ 2, 11, 20],
[ 4, 13, 22],
[ 5, 14, 23]])
===
In [84]: import skimage
In [85]: skimage.util.view_as_windows(xyz,(2,2,3),1).shape
Out[85]: (2, 2, 1, 2, 2, 3)
In [86]: skimage.util.view_as_windows(xyz,(2,2,3),1).reshape(4,4,3)
Out[86]:
array([[[ 1, 10, 19],
[ 2, 11, 20],
[ 4, 13, 22],
[ 5, 14, 23]],
[[ 2, 11, 20],
[ 3, 12, 21],
[ 5, 14, 23],
[ 6, 15, 24]],
[[ 4, 13, 22],
[ 5, 14, 23],
[ 7, 16, 25],
[ 8, 17, 26]],
[[ 5, 14, 23],
[ 6, 15, 24],
[ 8, 17, 26],
[ 9, 18, 27]]])
np.dstack. Looks like you are sliding across. So, maybe use sckit-image'sview_as_windowsthere.NxNhere? Is it always going to be 2x2 or is it going to beNxNfor the smaller matrices?