NumPy concatenate joins arrays along an existing axis with matching other dimensions
Joining arrays requires a rule about where the entries should meet. NumPy concatenate joins a sequence of arrays along an axis that already exists. Academia Master Trader explains the operation in English for readers in San Marino, using small constructed arrays. The examples keep the join direction and shape requirements visible, so the resulting arrangement is clear before any numerical interpretation is made.
Join two vectors in their supplied order
After import numpy as np, define x = np.array([2,5]) and y = np.array([8,11,14]). The call np.concatenate((x,y)) returns [2,5,8,11,14]. The entries from x come first, followed by the entries from y. The output remains one dimensional and has five entries.
The function does not sort, alternate or combine the numbers arithmetically. Reversing the input sequence to np.concatenate((y,x)) returns [8,11,14,2,5]. Input order is therefore part of the result. Write down that order when explaining the join rather than describing the output as an unordered collection.

Join rows along the first axis
Define a = np.array([[1,3],[5,7]]) and b = np.array([[9,11]]). The call np.concatenate((a,b),axis=0) returns [[1,3],[5,7],[9,11]]. The first array has two rows, the second has one, and both have two columns. The result has three rows and two columns.
The row counts can differ because axis zero is the dimension being joined. The column counts must match in this example. Each complete row from b can then follow the rows from a without leaving an undefined position in the rectangular output. The default axis is zero, so omitting the axis gives the same result here.
Join columns when the row counts match
Define c = np.array([[9],[11]]). The call np.concatenate((a,c),axis=1) returns [[1,3,9],[5,7,11]]. Both inputs have two rows. The first has two columns and the second has one, giving an output with two rows and three columns.
Although b and c contain the same two numerical values, their shapes are different. The one row shape of b suits the earlier vertical join, while the one column shape of c suits this horizontal join. Values alone do not determine compatibility. Check each input's number of dimensions and the lengths outside the selected join axis.
Flatten explicitly with axis None
The call np.concatenate((a,b),axis=None) returns [1,3,5,7,9,11]. With axis None, the input arrays are flattened before being joined. The output is a single vector rather than a matrix with three rows.
This setting can be useful when only the sequential entries are needed, but it removes the row grouping from the output shape. State that transformation rather than calling it the same join in another notation. A flattened vector and a three by two matrix have different shapes even when their entries appear in corresponding order.
Existing and new axes are different choices
Concatenate extends an existing axis; it does not create a new one to identify each input array. For the vector example, the two inputs become a longer vector. Their original boundary is not stored as a separate dimension in the result. If that boundary matters later, record the input lengths or choose an operation designed to introduce a new axis.
Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the input sequence, every input shape and the selected axis. Then check that the other dimensions match and that the joined dimension has the expected combined length. These checks make the arrangement explicit without assigning extra meaning to the joined values.








