. - " " . , 4x4x4 5x5x5 (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,1), 4.
, .
import numpy as np
from itertools import product
def iterslice(data_shape, width):
assert(all(sh>=width for sh in data_shape),
'all axes lengths must be at least equal to width')
start_indices = [range(sh-width+1) for sh in data_shape]
start_coords = product(*start_indices)
for start_coord in start_coords:
yield tuple(slice(coord, coord+width) for coord in start_coord)
arr = np.arange(0,5**3).reshape(5,5,5)
data_slices = iterslice(arr.shape, 3)
sub_arrays = [arr[ds] for ds in data_slices]