Saturday, December 21, 2019

Transpose and Flatten - Hacker Rank Solution

We 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.
Transpose and Flatten - Hacker Rank Solution
import numpy

N, M = map(int,raw_input().split())

my_array = numpy.array( [map(int, raw_input().split()) for i in range(N)] )
print numpy.transpose(my_array)
print my_array.flatten()

2 comments:

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

    ReplyDelete

Powered by Blogger.