The best way to add a dimension to a numpy array is
imm = imm[..., np.newaxis]
Don't worry, this isn't doing any expensive copying or anything, the underlying memory remains in place*. All that happens is the ndim increases by 1.
I think this solution is cleaner as you don't have to worry about grabbing the shape and putting it into reshape. It also has the advantage of you can quickly put the newaxis in any dimension. Say you wanted dimension 0 or 1 to be the new dimension
imm = imm[np.newaxis, ...] # new dimension is axis 0
imm = imm[:, np.newaxis, :] # new dimension is axis 1
imm = imm[:, :, np.newaxis] # new dimension is axis 2 (same as above)
* you can prove this to yourself by doing
x = np.array([1,2,3])
y = x[..., np.newaxis]
x *= 10
print(y)
#
# [[10]
# [20]
# [30]]