File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,11 @@ def crop_cube(cube: np.ndarray) -> np.ndarray:
1515 np.array: Cropped 3D Numpy byte array equivalent to cube, but with no zero padding
1616
1717 """
18- for i in range (cube .ndim ):
19- cube = np .swapaxes (cube , 0 , i )
20- nonzero_indices = np .any (cube != 0 , axis = tuple (range (1 , cube .ndim )))
21- cube = cube [nonzero_indices ]
22- cube = np .swapaxes (cube , 0 , i )
23- return cube
18+ nonzero_indices = np .where (cube != 0 )
19+ cropped_cube = cube [np .min (nonzero_indices [0 ]):np .max (nonzero_indices [0 ]) + 1 ,
20+ np .min (nonzero_indices [1 ]):np .max (nonzero_indices [1 ]) + 1 ,
21+ np .min (nonzero_indices [2 ]):np .max (nonzero_indices [2 ]) + 1 ]
22+ return cropped_cube
2423
2524
2625def expand_cube (cube : np .ndarray ) -> Generator [np .ndarray , None , None ]:
You can’t perform that action at this time.
0 commit comments