Convert 4D NIFTI to 3D

For neural network i need to convert my dataset from (220, 220, 120, 1) to (220, 220, 120) and affines from (1.0, 1.0, 1.0, 1.0) to (1.0, 1.0, 1.0). I tried to make it with
data_r=resample_img(data, target_affine=rescale_affine(data2.affine), target_shape=(220, 220, 120))
and result is (220, 220, 120, 1). What function or library can i use?

I think you can use numpy’s squeeze function after you load image and affine transformation as numpy arrays to throw array the last dimension, then save the newly shaped data to disk by dipy’s save_nifti function or use nibabel’s nifti1.Nifti1Image method to reconstruct the image on-the-fly.