clip

np.clip(ret_array, 0, 255)

swapaxes

a = np.arange(20).reshape(2, 2, 5)
print(a.shape)
print(a)
y = np.swapaxes(a, 1, 0)
print(y.shape)
print('y', y)

>>>
(2, 2, 5)
a [[[ 0  1  2  3  4]
  [ 5  6  7  8  9]]

 [[10 11 12 13 14]
  [15 16 17 18 19]]]

(2, 2, 5)
y [[[ 0  1  2  3  4]
  [10 11 12 13 14]]

 [[ 5  6  7  8  9]
  [15 16 17 18 19]]