Код: Выделить всё
# Let cube have shape (N, M, M)
sub_arrays = np.empty(len(cube), 3, 3)
row_start = ... # Shape (N,) and are integers in range [0, M-2]
row_end = ... # Shape (N,) and are integers in range [1, M-1]
col_start = ... # Shape (N,) and are integers in range [0, M-2]
col_end = ... # Shape (N,) and are integers in range [1, M-1]
# extract sub arrays from cube and put them in sub_arrays
for i in range(len(cube)):
# Note that the below is extracting a (3, 3) sub array from cube
sub_arrays[i] = cube[i, row_start[i]:row_end[i], col_start[i]:col_end[i]]
Код: Выделить всё
sub_arrays = cube[:, row_start:row_end, col_start:col_end]
Код: Выделить всё
TypeError: only integer scalar arrays can be converted to a scalar index
Подробнее здесь: https://stackoverflow.com/questions/793 ... top-1-d-ar