A NumPy array is a data structure that can be used to store single or multi-dimensional arrays or matrices. Those arrays can later be used for advanced mathematical operations like matrix operations. As we discussed in one of our previous articles, a NumPy array can be created from a Python list. In Python, we can also use linspace to create a NumPy array. In this article, we will discuss how to join two or more NumPy arrays.
In Python, we can use the concatenate() function to join two or more NumPy arrays. The joining can be done in two ways. If we want to join two arrays by combining the rows, then the axis parameter should be 0. In that case, both arrays should have the same number of columns.
import numpy array1 = numpy.array([[1, 2], [3, 4], [5, 6]]) array2 = numpy.array([[7, 8]]) print("array1: \n", array1) print("array2: \n", array2) array3 = numpy.concatenate((array1, array2), axis=0) print("array3: \n", array3)
The output of the above program will be:
array1: [[1 2] [3 4] [5 6]] array2: [[7 8]] array3: [[1 2] [3 4] [5 6] [7 8]]
Here, array1 and array2 …
0 Comments