Concatenate

Sort by

recency

|

462 Discussions

|

  • + 0 comments

    For Python3 Platform

    import numpy as np
    
    n, m, p = map(int, input().split())
    arr_1 = np.array([input().split() for _ in range(n)], int)
    arr_2 = np.array([input().split() for _ in range(m)], int)
    
    print(np.concatenate((arr_1, arr_2), axis=0))
    
  • + 0 comments
    import numpy as np
    N,M,P = map(int,input().split())
    array_1 = np.array([input().split() for _ in range(N)],int)
    array_2 = np.array([input().split() for _ in range(M)],int)
    print(np.concatenate((array_1,array_2), axis = 0))
    
  • + 1 comment

    My compact solution…

    import sys
    import numpy as np
    
    _ = input()  # We don't need N, M, or P.  Skip them!
    print(np.loadtxt(sys.stdin, int))
    

    This was a very, very poor problem. The challenge was to take the input, make two arrays with it, then concatenate them into one. However, if the input for the two arrays is instead read into a single array, there's no need to concatenate two arrays.

    With that in mind, here's a more facetious solution that doesn't use NumPy, but passes all the tests…

    import sys
    
    t = map(str.strip, sys.stdin.readlines()[1:])
    print('[[', ']\n ['.join(t), ']]', sep='')
    

    😛

    A better problem would've been to read in two arrays, then concatenate them in the opposite order.

  • + 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