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 numpy.concatenate() function | Python 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.vstac 2 min read Python | Numpy np.ma.concatenate() method np.ma.concatenate() method joins two or more masked arrays along an existing axis. It works similarly to np.concatenate() but it is specifically designed for masked arrays which may contain missing or invalid data that is "masked" i.e marked to be ignored in computations. Example:Pythonimport numpy 2 min read numpy.char.add() function in Python The add() method of the char class in the NumPy module is used for element-wise string concatenation for two arrays of str or unicode. numpy.char.add()Syntax : numpy.char.add(x1, x2)Parameters : x1 : first array to be concatenated (concatenated at the beginning)x2 : second array to be concatenated ( 1 min read numpy.ma.append() function | Python numpy.ma.append() function append the values to the end of an array. Syntax : numpy.ma.append(arr1, arr2, axis = None) Parameters : arr1 : [array_like] Values are appended to a copy of this array. arr2 : [array_like] Values are appended to a copy of this array. If axis is not specified, arr2 can be 2 min read numpy.fromstring() function â Python numpy.fromstring() function create a new one-dimensional array initialized from text data in a string. Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ') Parameters : string : [str] A string that contained the data. dtype : [data-type, optional] Data-type of the array. Default d 1 min read numpy.char.multiply() function in Python The multiply() method of the char class in the NumPy module is used for element-wise string multiple concatenation. numpy.char.multiply()Syntax : numpy.char.multiply(a, i)Parameters : a : array of str or unicodei : number of times to be repeatedReturns : Array of strings Example 1 : Using the method 1 min read numpy.append() in Python numpy.append() function is used to add new values at end of existing NumPy array. This is useful when we have to add more elements or rows in existing numpy array. It can also combine two arrays into a bigger one. Syntax: numpy.append(array, values, axis = None)array: Input array. values: The values 2 min read Numpy str_len() function numpy.char.str_len(arr) function is used for doing string operations in numpy. It returns the length of every string element wise. Parameters: arr : array_like of str or unicode.Input array. Returns : [ndarray] Output Array of integer. Code #1 : Python3 # Python program explaining # numpy.char.str_l 1 min read numpy.add() in Python NumPy, the Python powerhouse for scientific computing, provides an array of tools to efficiently manipulate and analyze data. Among its key functionalities lies numpy.add() a potent function that performs element-wise addition on NumPy arrays. numpy.add() SyntaxSyntax : numpy.add(arr1, arr2, /, out= 4 min read How to Concatenate two 2-dimensional NumPy Arrays? Sometimes it might be useful or required to concatenate or merge two or more of these NumPy arrays. In this article, we will discuss various methods of concatenating two 2D arrays. But first, we have to import the NumPy package to use it: # import numpy package import numpy as np Then two 2D arrays 4 min read Like