Shape and Reshape

Sort by

recency

|

387 Discussions

|

  • + 0 comments
    import numpy as np
    print(np.reshape(np.array(input().split(),int),(3,3)))
    
  • + 0 comments

    import numpy as np arr= np.array(list(map(int, input().split()))) shpa = arr.reshape(3,3) print(shpa)

  • + 0 comments

    import numpy a=list(map(int,input().split())) print(numpy.reshape(a,(3,3)))

  • + 0 comments

    My compact solution…

    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.

  • + 0 comments
    import numpy
    array= numpy.array(list(map(int, input().split())))
    print(numpy.reshape(array, (3,3)))