I have a 3D array and would like to break it into many sub-selections. This is my code:
arr = trainMasks[0, 0, :, :, :]
crop = 3
arrs = [arr[x:-(crop - x), y:-(crop - y), z:-(crop - z)]
for x in range(crop + 1)
for y in range(crop + 1)
for z in range(crop + 1)]
- If I use
x in range(crop), xonly matches to crop - 1, the last record in dimension x always drops out - If I use
x in range(crop+1), xit rises up crop, leading to a fragment arr[crop:-0, ...]that has the form[0, y_dim, z_dim]
I know the usual answer, simply remove the upper limit, for example arr[crop:, :, :]. This is usually quite convenient. But how to do this in understanding the list?
source
share