The problem is in this line:
imat = mat
Instead you should do this, to allocate a new 4x4 matrix at the beginning:
imat = [[0]*4 for _ in xrange(4)]
What's happening is that you didn't initialize imat
correctly, you only assigned a reference to mat
so both objects are one and the same, so no modification is being performed. Also, a much simpler alternative for transposing a matrix would be:
imat = [list(m) for m in zip(*mat)]