I want to split a 3d matrix into smaller matrixes of equal size. In this case a 4x4x3 matrix into 4 individual matrices of 2x2x3. I am trying this:
import numpy as np
from skimage.util.shape import view_as_windows
#create 4x4
data = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]])
#make 3 dimensional
stacked = np.dstack([data, data, data])
#split it
windows = view_as_windows(stacked, (2,2,3))
but windows.shape
returns (3, 3, 1, 2, 2, 3)
when I am expecting something more like (4, 2, 2, 3)
, or even a list of matrices which has length 4 and is (2,2,3)
I don't need to use skimage to do this, numpy are else is fine.
If this were a 2d problem with data
and input (4,4)
I would expect the output to be 4 matrixes:
[[1,2,
5,6]]
[[3,4,
7,8]]
[[9,10,
13,14]]
[[11,12,
15,16]]