are two two-dimensional arrays. array1 has three rows and two columns. Array2 has one row and two columns. We are using the concatenate() function to join the two NumPy arrays. The new array is array3. array3 has 4 rows and two columns. So, the rows of array1 and array2 got combined.
Similarly, we can join two NumPy arrays by combining the columns. In that case, the two input arrays should have the same number of rows.
import numpy
array4 = numpy.array([[1, 2], [3, 4], [5, 6]])
array5 = numpy.array([[7], [8], [9]])
print("array4: \n", array4)
print("array5: \n", array5)
array6 = numpy.concatenate((array4, array5), axis=1)
print("array6: \n", array6)
The output of the above program will be:
array4: [[1 2] [3 4] [5 6]] array5: [[7] [8] [9]] array6: [[1 2 7] [3 4 8] [5 6 9]]
Here, array4 and array5 have the same number of rows. So, we can use the concatenate() function to join the arrays by combining the columns by using axis=1.







































0 Comments