I am working with 3d images. If I have a single image tensor of size d x w x h, I would like to extract many (~100) same-sized (e.g. 32 x 32 x 32) 3d patches defined by a tensor of size (n_patches x 3) corresponding to the minimum value (in each of 3 dimensions) of each patch.

Ideally, the output would be a n_patches x 32 x 32 x 32 tensor containing all of the extracted patches.

Is there a more elegant/quick way to do this indexing without looping n_patches times and concatenating the patches?