numpy.concatenate() function in Python Last Updated : 13 May, 2025 Comments Improve Suggest changes Like Article Like Report The numpy.concatenate() function combines multiple arrays into a single array along a specified axis. This function is particularly useful when working with large datasets or performing operations that require merging data from different sources. Unlike other array-joining functions like numpy.vstack() , numpy.hstack() which only join arrays vertically or horizontally numpy.concatenate() provides greater flexibility by allowing you to specify the axis along which the arrays are joined.Syntax of numpy.concatenate()The syntax for the numpy.concatenate() function is as follows:numpy.concatenate((array1, array2, ...), axis=0, out=None, dtype=None)Parameters:arrays: A sequence of input arrays to be concatenated. These arrays must have the same shape along all axes except the one specified by axis.axis: The axis along which the arrays will be joined. Default is 0 (the first axis).out: If provided the result will be placed in this array.dtype: It overrides the data type of the output array.Key Features of numpy.concatenate()Flexible Axis Specification : You can concatenate arrays along any axis make it versatile for multi-dimensional data.Data Compatibility : The arrays must have matching shapes along all axes except the one being concatenated.Efficient Memory Usage : The function creates a new array but shares the underlying data from the input arrays when possible.Supports Higher Dimensions : Works easily with 1D, 2D and higher-dimensional arrays.Examples of Using numpy.concatenate()Let us now look at some practical examples to understand how numpy.concatenate() worksExample 1: Concatenating 1D ArraysSuppose you have two 1D arrays and want to combine them into a single array. Python import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) result = np.concatenate((arr1, arr2)) print("Result:", result) Output : Result: [1 2 3 4 5 6]Example 2: Concatenating 2D Arrays Along Rows (axis=0)For 2D arrays you can concatenate along rows (default behavior) or columns Python arr1 = np.array([[1, 2], [3, 4]]) arr2 = np.array([[5, 6]]) result = np.concatenate((arr1, arr2), axis=0) print("Result:\n", result) Output : numpy_concatenateComparison with Other FunctionsWhile numpy.concatenate() is versatile there are other functions in NumPy that perform similar tasks:numpy.vstack() :Stacks arrays vertically along rows equivalent to axis=0.Limited to stacking along the first axis. numpy.hstack():Stacks arrays horizontally along columns equivalent to axis=0.Limited to stacking along the second axis.numpy.append():Appends values to an array along a specified axis.Less efficient than because it creates a copy of the original array.For scenarios which require flexibility and efficiency numpy.concatenate() is the preferred choice. Comment More infoAdvertise with us Next Article numpy.concatenate() function in Python sanjoy_62 Follow Improve Article Tags : Machine Learning Python-numpy Python numpy-arrayManipulation python Practice Tags : Machine Learningpython Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Machine Learning Tutorial Machine learning is a branch of Artificial Intelligence that focuses on developing models and algorithms that let computers learn from data without being explicitly programmed for every task. In simple words, ML teaches the systems to think and understand like humans by learning from the data.It can 5 min read Linear Regression in Machine learning Linear regression is a type of supervised machine-learning algorithm that learns from the labelled datasets and maps the data points with most optimized linear functions which can be used for prediction on new datasets. It assumes that there is a linear relationship between the input and output, mea 15+ min read Support Vector Machine (SVM) Algorithm Support Vector Machine (SVM) is a supervised machine learning algorithm used for classification and regression tasks. It tries to find the best boundary known as hyperplane that separates different classes in the data. It is useful when you want to do binary classification like spam vs. not spam or 9 min read Logistic Regression in Machine Learning Logistic Regression is a supervised machine learning algorithm used for classification problems. Unlike linear regression which predicts continuous values it predicts the probability that an input belongs to a specific class. It is used for binary classification where the output can be one of two po 11 min read K means Clustering â Introduction K-Means Clustering is an Unsupervised Machine Learning algorithm which groups unlabeled dataset into different clusters. It is used to organize data into groups based on their similarity. Understanding K-means ClusteringFor example online store uses K-Means to group customers based on purchase frequ 4 min read K-Nearest Neighbor(KNN) Algorithm K-Nearest Neighbors (KNN) is a supervised machine learning algorithm generally used for classification but can also be used for regression tasks. It works by finding the "k" closest data points (neighbors) to a given input and makesa predictions based on the majority class (for classification) or th 8 min read 100+ Machine Learning Projects with Source Code [2025] This article provides over 100 Machine Learning projects and ideas to provide hands-on experience for both beginners and professionals. Whether you're a student enhancing your resume or a professional advancing your career these projects offer practical insights into the world of Machine Learning an 5 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read Introduction to Convolution Neural Network Convolutional Neural Network (CNN) is an advanced version of artificial neural networks (ANNs), primarily designed to extract features from grid-like matrix datasets. This is particularly useful for visual datasets such as images or videos, where data patterns play a crucial role. CNNs are widely us 8 min read Like