# Author: Steven Carr # Last Edited: November 2021 # Program that transposes a matrix import stdarray import stdio import sys # Accept m (int) and n (int) as command-line arguments. m = int(sys.argv[1]) n = int(sys.argv[2]) # Accept m x n floats from standard input and store them in a 2D list a. a = [] for i in range(m): a2 = [] for j in range(n): a2.append(stdio.readFloat()) a.append(a2) # Set c (the transpose of a) to a 2D list with n rows and m columns, with all the elements # initialized to 0.0 c = [] for i in range(n): c2 = [] for j in range(m): c2.append(a[j][i]) c.append(c2) # Fill in the elements of c such that c[i][j] = a[j][i], where 0 <= i < n and 0 <= j < m. for i in range(n): for j in range(m): if j != m-1: stdio.write(str(c[i][j]) + ' ') else: stdio.writeln(c[i][j])