Transpose and Flatten

Sort by

recency

|

320 Discussions

|

  • + 0 comments

    import numpy as np

    n,m = input().split() arr = [] for i in range(int(n)): num = list(map(int, input().split())) arr.append(num) myarr = np.array(arr) print(np.transpose(myarr)) print(myarr.flatten())

  • + 0 comments
    import numpy as np
    
    N, M = map(int, input().split())
    elements=[]
    
    for _ in range(N):
        elements.append(list(map(int, input().split())))
    
    array = np.array(elements)
    print(array.transpose())
    print(array.flatten())
    
  • + 0 comments

    MY SOLUTION

    import numpy n,m = list(map(int,input().split())) l = [] for i in range(n): b= list(map(int,input().split())) l.append(b)

    a = numpy.array(l) print(numpy.transpose(a)) print(a.flatten())

  • + 0 comments

    import numpy as np

    rows, cols = map(int, input().split())

    arr = [list(map(int, input().split())) for _ in range(rows)]

    arr = np.array(arr, dtype=int)

    print(np.transpose(arr))

    print(arr.flatten())

  • + 0 comments

    Simple Noobie approach -

    import numpy as np
    
    rows, columns = map(int, input().split())
    lst = []
    
    for row in range(rows):
        inp = input().strip().split()
        lst.append(inp)
        arr = np.array(lst)
    
    arr = arr.astype(int)
    print(np.transpose(arr))
    print(arr.flatten())