Concatenate

Sort by

recency

|

459 Discussions

|

  • + 0 comments

    import numpy as np

    n,m,p = map(int,input().split()) ar1 = np.array([input().split() for i in range(n)], int) ar2 = np.array([input().split() for i in range(m)], int)

    print(np.concatenate((ar1,ar2), axis=0))

  • + 0 comments

    Here is HackerRank Concatenate in Python solution - https://programmingoneonone.com/hackerrank-concatenate-problem-solution-in-python.html

  • + 0 comments
    import numpy as np
    
    n, m, p = map(int, input().split())
    
    arr1 = np.array([input().split() for i in range(n)], int)
    arr2 = np.array([input().split() for i in range(m)], int)
    
    print(np.concatenate((arr1, arr2), axis=0))
    
  • + 0 comments

    I get what we're going for here, but I can't help but notice that none of the methods this was probably designed to test are actually necessary. There's no reason to concatenate, or handle the length of each array, nor worry about which axis it will be joined on, because the damn input is already formatted as a 2d array!

    import numpy as np
    
    # we don't need the first row, toss it:
    _ = input()
    
    data = []
    
    # assign each input() result to a variable and append it to our empty list:
    while True:
        try:
            line = input()
            data.append(list(map(int, line.split())))
        except EOFError:
            break
    
    # change the list to an array and print it:
    arr = np.array(data)
    print(arr)
    
    `
    
  • + 0 comments

    I get what we're going for here, but I can't help but notice that none of the methods this was probably designed to test are actually necessary. There's no reason to concatenate, or handle the length of each array, nor worry about which axis it will be joined on, because the damn input is already formatted as a 2d array!

    import numpy as np
    
    # we don't need the first row, toss it:
    _ = input()
    
    data = []
    
    # assign each input() result to a variable and append it to our empty list:
    while True:
        try:
            line = input()
            data.append(list(map(int, line.split())))
        except EOFError:
            break
    
    arr = np.array(data)
    print(arr)
    
    `