Exercise 5. (Transpose) Write a program called transpose.py that accepts m (int) and n (int) as command-line arguments,
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Exercise 5. (Transpose) Write a program called transpose.py that accepts m (int) and n (int) as command-line arguments,
Exercise 5. (Transpose) Write a program called transpose.py that accepts m (int) and n (int) as command-line arguments, mxn floats from standard input representing the elements of an mxn matrix a, and writes to standard output the transpose of a. >/workspace/project3 $ python3 transpose py 2 2 1234 <enter> 1.0 3.0 $ python3 transpose py 2 3 123456 <enter> 1.0 4.0 2.0 5.0
mport stdarray mport stdio Import sys #Accept m (int) and n (int) as command-Line arguments. n = int(sys.argv[1]) = int(sys.argv[2]) #Accept m x n floats from standard input and store then in a 20 list a. a = stdarray.create20(m, n, None) for i in range(n): for j in range(n): | a[j] = (stdio.readFloat()) print(a) # Set c (the transpose offa) to a 2D List with a rows and m columns, with all the elements # initialized to 8.8 c= stdarray.create2D(n, n, 0.0) #Fill in the elements of c such that c[j] = a[j][1], where 0 <=i<n and @ <= j <a. for i in range(a): 3 for j in range(n): if 0 <=i<n and <=j< m: c[j] = a[j][1] #Write c to standard output. for i in range(n): TO for 1 in range(n):
print(a) # Set e (the transpose of a) to a 20 list with n rows and a cetumns, with all the elements A# initialized to 8.0 ce stdarray.create20(m, n, e Fill in the elements of c such that c[j] = a[j][1], where @ for à in range(n): for in range(n): ifeien and e[j] = a[j][1] # Write c to standard output. for i in range(n): for j in range(n): I ifjl= n - 1: # If j is not the last column, write o[1][1] with a space after. stdio.write(fie[1][j]}') enspoes.gr/ #Otherwise, write the element with a newline after.. stdio.writeln(e[1][j])
/Users/Bootygoblin/Downloads/cs118_programming exami 1.0 2.0 3.0 4.0 5.0 6.0 [[1.8, 2.0], [3.0, 4.0], [5.0, 6.0]] 1.0 3.0 2.0 4.0 8.8 8.8 Process finished with exit code 6 1