Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Transpose and Flatten problem solution in python

YASH PAL, 31 July 2024

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.

HackerRank Transpose and Flatten solution in python

Problem solution in Python 2 programming.

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()

Problem solution in Python 3 programming.

import numpy
n, 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 python

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions