Transpose and Flatten

  • + 0 comments
    import numpy as np
    
    # Input number of rows and columns
    rows, cols = map(int, input().split())
    
    data = []
    for _ in range(rows):
        row = list(map(int, input().split()))
        data.append(row)
    
    # Convert the list of lists to a NumPy array
    array = np.array(data)
    print(np.transpose(array))
    print(array.flatten())