Hackerrank Shape and Reshape Solution

Hackerrank Shape and Reshape Solution

Solution in python3

Approach 1.

import numpy
print( numpy.array(input().split(" "),int).reshape(3,3) )

Approach 2.

import numpy
l=input().split()
a=numpy.array(l,int)
a.shape=(3,3)
print(a)

Approach 3.

import numpy
A = numpy.array(input().strip().split(),int)
print(numpy.reshape(A,(3,3)))

Solution in python

Approach 1.

import numpy
print numpy.reshape(numpy.array(map(int,raw_input().split())),(3,3))

Approach 2.

import numpy
print(numpy.array(str(raw_input()).strip().split(), int).reshape(3,3))

Approach 3.

import numpy
ar = numpy.array(map(int,raw_input().split()))
ar.shape = (3,3)
print ar

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe