HackerRan Shape and Reshape problem solution in Python YASH PAL, 31 July 202417 January 2026 HackerRan Shape and Reshape problem solution in Python – In this Shape and Reshape problem You have given a space-separated list of nine integers. Your task is to convert this list into a 3 X 3 NumPy array.shape The shape tool gives a tuple of array dimensions and can be used to change the dimensions of an array.(a). Using shape to get array dimensionsimport numpy my__1D_array = numpy.array([1, 2, 3, 4, 5]) print my_1D_array.shape #(5,) -> 1 row and 5 columns my__2D_array = numpy.array([[1, 2],[3, 4],[6,5]]) print my_2D_array.shape #(3, 2) -> 3 rows and 2 columns (b). Using shape to change array dimensions import numpy change_array = numpy.array([1,2,3,4,5,6]) change_array.shape = (3, 2) print change_array #Output [[1 2] [3 4] [5 6]] reshapeThe reshape tool gives a new shape to an array without changing its data. It creates a new array and does not modify the original array itself.import numpy my_array = numpy.array([1,2,3,4,5,6]) print numpy.reshape(my_array,(3,2)) #Output [[1 2] [3 4] [5 6]]HackerRank Shape and Reshape problem solution in Python 2.import numpy s = numpy.array(map(int, raw_input().split())) print numpy.reshape(s, (3,3))Shape and Reshape solution in Python 3.import numpy as np print(np.array(input().split(),int).reshape(3,3)) Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT import numpy ss=raw_input().strip().split() ss=[int(i) for i in ss] my_array = numpy.array(ss) print numpy.reshape(my_array,(3,3))Problem solution in pypy3 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT a = list(map(int, input().split())) for i in range(len(a)//3): if i == 0: print('[[' + ' '.join(map(str, a[0:3])) + ']') elif i == 1: print(' [' + ' '.join(map(str, a[3:6])) + ']') elif i == 2: print(' [' + ' '.join(map(str, a[6:9])) + ']]') coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython