numpy.concatenate() function | Python (original) (raw)
Last Updated : 22 Apr, 2020
numpy.concatenate()
function concatenate a sequence of arrays along an existing axis.
Syntax : numpy.concatenate((arr1, arr2, …), axis=0, out=None)
Parameters :
arr1, arr2, … : [sequence of array_like] The arrays must have the same shape, except in the dimension corresponding to axis.
axis : [int, optional] The axis along which the arrays will be joined. If axis is None, arrays are flattened before use. Default is 0.
out : [ndarray, optional] If provided, the destination to place the result. The shape must be correct, matching that of what concatenate would have returned if no out argument were specified.
Return : [ndarray] The concatenated array.
Code #1 :
import
numpy as geek
arr1
=
geek.array([[
2
,
4
], [
6
,
8
]])
arr2
=
geek.array([[
3
,
5
], [
7
,
9
]])
gfg
=
geek.concatenate((arr1, arr2), axis
=
0
)
print
(gfg)
Output :
[[2 4] [6 8] [3 5] [7 9]]
Code #2 :
import
numpy as geek
arr1
=
geek.array([[
2
,
4
], [
6
,
8
]])
arr2
=
geek.array([[
3
,
5
], [
7
,
9
]])
gfg
=
geek.concatenate((arr1, arr2), axis
=
1
)
print
(gfg)
Output :
[[2 4 3 5] [6 8 7 9]]
Code #3 :
import
numpy as geek
arr1
=
geek.array([[
2
,
4
], [
6
,
8
]])
arr2
=
geek.array([[
3
,
5
], [
7
,
9
]])
gfg
=
geek.concatenate((arr1, arr2), axis
=
None
)
print
(gfg)
Output :
[2 4 6 8 3 5 7 9]
Similar Reads
- Python | Numpy np.ma.concatenate() method With the help of np.ma.concatenate() method, we can concatenate two arrays with the help of np.ma.concatenate() method. Syntax : np.ma.concatenate([list1, list2]) Return : Return the array after concatenation. Example #1 : In this example we can see that by using np.ma.concatenate() method, we are a 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.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 ( 2 min read
- Numpy ndarray.flatten() function in Python The flatten() function is used to convert a multi-dimensional NumPy array into a one-dimensional array. It creates a new copy of the data so that original array stays unchanged. If your array has rows and columns or even more dimensions, then flatten() line up every single value into a straight list 3 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 value 2 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.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
- numpy.multiply() in Python The numpy.multiply() is a numpy function in Python which is used to find element-wise multiplication of two arrays or scalar (single value). It returns the product of two input array element by element. Syntax: numpy.multiply(arr1, arr2, out=None, where=True, casting='same_kind', order='K', dtype=No 3 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 5 min read