Shape and Reshape

Sort by

recency

|

380 Discussions

|

  • + 0 comments
    A= numpy.reshape([list(map(int,input().split()))],(3,3))
    
  • + 0 comments

    import numpy user_input = input().split() user_input = numpy.array(user_input,dtype = 'int') print(numpy.reshape(user_input,(3,3)))

    Check this out :)

  • + 0 comments

    import numpy

    inp=list(map(int,input().split())) change_array=numpy.array(inp) change_array.shape=(3,3) print(change_array)

  • + 0 comments
    import numpy as np
    a1 = [*map(int, input().split())] 
    a1 = np.array(a1)
    print(np.reshape(a1, (3, 3)))
    

    Explanation: * input() -> takes in the input * .split() -> turns the input into a list of strings. ie. ["1", "2", "3", etc] * map(int, ...) -> turns the list of strings into integers * np.array(a1) -> Turns the list into a numpy array * np.reshape(a1, (3,3)) -> makes the array to be 3x3

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