Implementation of matrix tarnspose function.