HackerRank Transpose and Flatten problem solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Transpose and Flatten problem solution in Python – In this Transpose and Flatten problem, You are given a N X M integer array matrix with space-separated elements (N = rows and M = columns). Your task is to print the transpose and flatten results.TransposeWe can generate the transposition of an array using the tool numpy.transpose.It will not affect the original array, but it will create a new array.import numpy my_array = numpy.array([[1,2,3], [4,5,6]]) print numpy.transpose(my_array) #Output [[1 4] [2 5] [3 6]] FlattenThe tool flatten creates a copy of the input array flattened to one dimension.import numpy my_array = numpy.array([[1,2,3], [4,5,6]]) print my_array.flatten() #Output [1 2 3 4 5 6]HackerRank Transpose and Flatten solution in Python 2.import numpy N, M = map(int, raw_input().split()) s = numpy.array([map(int, raw_input().split()) for _ in range(N)]) print numpy.transpose(s) print s.flatten()Transpose and Flatten solution in Python 3.import numpyn, m = map(int, input().split())array = numpy.array([input().strip().split() for _ in range(n)], int)print (array.transpose())print (array.flatten())Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT import numpy n,m = map(int, raw_input().split()) a = numpy.array([raw_input().split() for _ in xrange(n)], int) print (a.transpose()) print (a.flatten())Problem solution in pypy3 programming.import numpy narr = numpy.array([input().split() for _ in range(int(input().split()[0]))],int) print (narr.transpose()) print (narr.flatten()) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython