Question 2 - Transpose and Flatten
Task
You are given an NxM integer array matrix with space-separated elements (N= rows and M= columns).
The question is to print the transpose and flatten the results.
Input Format
Output Format
First, print the transpose array and then print the flatten.
Sample Input
2 2
1 2
3 4
Sample Output
[[1 3]
[2 4]]
[1 2 3 4]
Solution:
import numpy
n,m = map(int,input().split())
arr = numpy.array([ list(map(int,input().split())) for _ in range(n)])
print(numpy.transpose(arr),arr.flatten(),sep="\n")
No comments:
Post a Comment