We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import numpy as np
print(np.array(input().split(), int).reshape((3,3)))
My solution shows another way to use reshape. The problem statement ony discussed reshaping by setting a value in the shape property of an array object or by calling the np.reshape() function from the NumPy module. However, it is available as a method of array objects, too. Using that method, I was able to create the array and reshape it all in one line, using a fluent style of coding.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Shape and Reshape
You are viewing a single comment's thread. Return to all comments →
My compact solution…
My solution shows another way to use
reshape
. The problem statement ony discussed reshaping by setting a value in theshape
property of an array object or by calling thenp.reshape()
function from the NumPy module. However, it is available as a method of array objects, too. Using that method, I was able to create the array and reshape it all in one line, using a fluent style of coding.