Doubt in numpy quiz

Does np.concatenate((a,b), axis = 0) concatenate 2 arrays horizontally or vertically. When I ran this function, it seemed that the two arrays are concatenated vertically but there is a question in quiz whose answer says that this function conatenates 2 arrays horizontally.

Hey @abhaygarg2001, it depends on the axis parameter that you pass in the function. In your case it is 0, hence if we have two numpy arrays as a and b, then you would get the output as shown below :

a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b), axis=0)

Output:

array([[1, 2],
       [3, 4],
       [5, 6]]) 

Now it’s upto you whether to call it vertically or horizontally. It is confusing because the array is combined vertically but the axis across which it has combined is horizontal.

Hope this helps.
Happy Learning :slight_smile: