In this article, we will learn how to concatenate a NumPy array to another NumPy array in python.
Table Of Contents
 Using append() method to concatenate NumPy Arrays
 Using concatenate() method to concatenate NumPy Arrays
 Using hstack() method to Concatenate NumPy Arrays
 Using vstack() to Concatenate NumPy Arrays rowwise (vertically)
Given two NumPy arrays, we need to add the 2nd array at the end of first array.
Example: 1st NumPy Array = [ 1 2 3 4 5 ] 1st NumPy Array = [ 6 7 8 9 10 ] After concatenating two NumPy Arrays, the final NumPy Array must be like: [ 1 2 3 4 5 6 7 8 9 10]
There are multiple ways to concatenate a NumPy array to another NumPy array. Let’s discuss all the methods one by one with proper approach and a working code example
1.) Using append() method to concatenate NumPy Arrays
Numpy module in python, provides a function numpy.append() to add objects to the end of an array, The object should be an array like. The append method will take array, object to be appended as arguments. It will append the given object at the end of the array and returns the array.
Syntax of append()
numpy.append(arr, values, axis=None)
Parameters:
arr = The array to be passed to the function. values = array_like object to appended to array. axis = int, optional, Axis along which to append values.
Return:
Returns array with values appended at end.
In this case, to concatenate two numpy arrays we need to pass two arrays to the append() method. It will return the concatenated array.
Approach
 Import numpy library and create two numpy arrays
 Now pass the array1, array2 to the append() method.
 The method will return return of a copy of the concatenated array.
 Print the concatenated array
Source code
import numpy as np # create numpy arrays arr1 = np.array([1, 2, 3, 4, 5]) arr2 = np.array([6, 7, 8, 9, 10]) #concatenating two arrays using append() method arr = np.append(arr1, arr2) # printing the concatenated array print(" The concatenated array is = ", arr)
OUTPUT:
The concatenated array is = [ 1 2 3 4 5 6 7 8 9 10]
2.) Using concatenate() method to concatenate NumPy Arrays
Numpy module in python, provides a function numpy.concatenate() to join a sequence of arrays along an existing axis. The concatenate method will take a sequence of arrays as parameters. It will concatenate the arrays into one single array and returns the concatenated array.
Now to concatenate two arrays, In the sequence of arrays we will pass the given two arrays, The concatenate() method will return the concatenated array.
Example
concatenate(( [1 2 3 4 5 6] , [6 7 8 9 10] )) ==> [ 1 2 3 4 5 6 7 8 9 10]
Syntax of concatenate()
numpy.concatenate((a1, a2, ...), axis=0)
Parameters:
(a1, a2, ...) = Sequence of arrays to be passed to the function. axis = int, optional, Axis along which to concatenate arrays.
Return:
Returns a concatenated array.
Approach
 Import numpy library and create two numpy arrays
 Now pass the array1, array2 as a sequence of arrays to the concatenate method
 The method will return return of a copy of the concatenated array.
 Print the concatenated array
Source code
import numpy as np # create numpy arrays arr1 = np.array([1, 2, 3, 4, 5]) arr2 = np.array([6, 7, 8, 9, 10]) #concatenating two arrays using concatenate() method arr = np.concatenate((arr1, arr2)) # printing the concatenated array print(" The concatenated array is = ", arr)
OUTPUT:
The concatenated array is = [ 1 2 3 4 5 6 7 8 9 10]
3.) Using hstack() method to Concatenate NumPy Arrays
Numpy module in python, provides a function numpy.hstack() function is used to stack the sequence of input arrays horizontally i.e, concatenating into a single array. The hstack method will take a sequence of arrays as parameters. It will concatenate the arrays into one single array and returns the array. The hstack is equivalent to concatenation.
Now to concatenate two arrays, In the sequence of arrays we will pass the given two arrays, The hstack() method will return the concatenated array.
Example
hstack( ([1 2 3 4 5] , [6 7 8 9 10]) ) ==> [ 1 2 3 4 5 6 7 8 9 10]
Syntax of hstack()
numpy.hstack(tuple_of_arrays)
Parameters:
tuple_of_arrays = Sequence of arrays to be passed to the function.
Return:
Returns The array formed by stacking the given arrays.
Approach
 Import numpy library and create two numpy arrays
 Now pass the array1, array2 as a sequence of arrays to the hstack method
 The method will return return of a copy of the concatenated array.
 Print the concatenated array
Source code
import numpy as np # create numpy arrays arr1 = np.array([1, 2, 3, 4, 5]) arr2 = np.array([6, 7, 8, 9, 10]) #concatenating two arrays using hstack() arr = np.hstack((arr1, arr2)) # printing the concatenated array print(" The concatenated array is = ", arr)
OUTPUT:
The concatenated array is = [ 1 2 3 4 5 6 7 8 9 10]
4.) Using vstack() to Concatenate NumPy Arrays rowwise (vertically)
Numpy module in python, provides a function numpy.vstack() function is used to Stack arrays in sequence vertically (rowwise). i.e, concatenating into a single array. The vstack method will take a sequence of arrays as parameters. It will stack the arrays into one single array and returns the array. The vstack is equivalent to vertical concatenation.
Now to Concatenate two arrays vertically (rowwise), we will pass the given two arrays to the vstack() method and it will return the concatenated (stacked) array.
Example
vstack( ([1 2 3 4 5] , [6 7 8 9 10]) )
Syntax of vstack()
numpy.vstack(tuple_of_arrays)
Parameters:
tuple_of_arrays = sequence of arrays to be passed to the function.
Return:
Returns The array formed by stacking the given arrays.
Approach
 Import numpy library and create two numpy arrays
 Now pass the array1, array2 as a sequence of arrays to the vstack method
 The method will return return of a copy of the concatenated array.
 Print the concatenated array
Source code
import numpy as np # create numpy arrays arr1 = np.array([1, 2, 3, 4, 5]) arr2 = np.array([6, 7, 8, 9, 10]) #concatenating two arrays vertically (rowwise) arr = np.vstack((arr1, arr2)) # printing the concatenated array print(" The concatenated array is:") print(arr)
OUTPUT:
The concatenated array is: [[ 1 2 3 4 5] [ 6 7 8 9 10]]
Summary
Great! you made it, We have discussed all possible methods to concatenate a NumPy array to another NumPy array. Happy learning.
Pandas Tutorials Learn Data Analysis with Python

Pandas Tutorial Part #1  Introduction to Data Analysis with Python

Pandas Tutorial Part #2  Basics of Pandas Series

Pandas Tutorial Part #3  Get & Set Series values

Pandas Tutorial Part #4  Attributes & methods of Pandas Series

Pandas Tutorial Part #5  Add or Remove Pandas Series elements

Pandas Tutorial Part #6  Introduction to DataFrame

Pandas Tutorial Part #7  DataFrame.loc[]  Select Rows / Columns by Indexing

Pandas Tutorial Part #8  DataFrame.iloc[]  Select Rows / Columns by Label Names

Pandas Tutorial Part #9  Filter DataFrame Rows

Pandas Tutorial Part #10  Add/Remove DataFrame Rows & Columns

Pandas Tutorial Part #11  DataFrame attributes & methods

Pandas Tutorial Part #12  Handling Missing Data or NaN values

Pandas Tutorial Part #13  Iterate over Rows & Columns of DataFrame

Pandas Tutorial Part #14  Sorting DataFrame by Rows or Columns

Pandas Tutorial Part #15  Merging or Concatenating DataFrames

Pandas Tutorial Part #16  DataFrame GroupBy explained with examples
Are you looking to make a career in Data Science with Python?
Data Science is the future, and the future is here now. Data Scientists are now the most soughtafter professionals today. To become a good Data Scientist or to make a career switch in Data Science one must possess the right skill set. We have curated a list of Best Professional Certificate in Data Science with Python. These courses will teach you the programming tools for Data Science like Pandas, NumPy, Matplotlib, Seaborn and how to use these libraries to implement Machine learning models.
Checkout the Detailed Review of Best Professional Certificate in Data Science with Python.
Remember, Data Science requires a lot of patience, persistence, and practice. So, start learning today.