Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

HackerRan Shape and Reshape problem solution in python

YASH PAL, 31 July 2024

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.

HackerRan Shape and Reshape solution in python

Problem solution in Python 2 programming.

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

Problem solution in Python 3 programming.

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 Python Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes