In this Concatenate problem, You are given two integer arrays of size N X P and M X P ( N & M are rows, and P is the column). Your task is to concatenate the arrays along axis 0.

HackerRank Concatenate solution in python


Problem solution in Python 2 programming.

import numpy
N, M, P = map(int, raw_input().split())
n = numpy.array([map(int, raw_input().split()) for _ in range(N)])
m = numpy.array([map(int, raw_input().split()) for _ in range(M)])
print numpy.concatenate((n, m))


Problem solution in Python 3 programming.

import numpy as np
a, b, c = map(int,input().split())
arrA = np.array([input().split() for _ in range(a)],int)
arrB = np.array([input().split() for _ in range(b)],int)
print(np.concatenate((arrA, arrB), axis = 0))


Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

import numpy
n, m, p=map(int, raw_input().split())
g=[]
for i in range(n+m):
    g.append(map(int, raw_input().split()))
print numpy.reshape(g, (n+m, p))


Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
def matrix_printer(arr,n,m):
    for i in range(n):
        if i == 0:
            print('[[' + ' '.join(map(str, arr[0][0:m])) + ']')
        elif i == n-1:
            print(' [' + ' '.join(map(str, arr[n-1][0:m])) + ']]')
        else:
            print(' [' + ' '.join(map(str, arr[i][0:m])) + ']')
                
n,m,p = map(int, input().split())
lst=[]
for _ in range(n+m):
    lst.append(list(map(int,input().split())))

matrix_printer(lst,(n+m),p)