Declared and implemented transpose function.