python-scipyHow do I join two arrays using Python and NumPy?
Joining two arrays using Python and NumPy is done using the np.concatenate()
function. It takes a sequence of arrays and combines them into a single array.
Example code
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a, b))
print(c)
Output example
[1 2 3 4 5 6]
The code above contains the following parts:
import numpy as np
imports the NumPy library into the program.a = np.array([1, 2, 3])
andb = np.array([4, 5, 6])
create two NumPy arrays.np.concatenate((a, b))
joins the two arrays into a single array.print(c)
prints the result of the concatenation.
Helpful links
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How can I check if a certain version of Python is compatible with SciPy?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How can I use Python and SciPy to visualize data?
- How do I create a numpy array of zeros using Python?
- How do I use the numpy vstack function in Python?
- How do I use the NumPy transpose function in Python?
- How can I use Python and SciPy to find the zeros of a function?
- How do I uninstall Python Scipy?
See more codes...