In this HackerRank Shape and Reshape problem solution You are given a space-separated list of nine integers. Your task is to convert this list into a 3X3 NumPy array.

HackerRank Shape and Reshape in python problem solution

HackerRank Shape and Reshape in python problem solution

import numpy
str_input=raw_input()
str_input1= str_input.split(" ")
a=numpy.array([],int)
for i in range(len(str_input1)):
    test=int(str_input1[i])
    a=numpy.append(a,test)
#a.shape = (3, 3)
reshape_val=int(numpy.sqrt(len(str_input1)))
print numpy.reshape(a,(reshape_val,reshape_val))