python-scipyHow do I use the append function in Python Numpy?
The append() function in Python Numpy is used to combine two arrays. It takes in two parameters, the first being the array to which the other is appended. The second parameter is the array which is appended to the first. The append() function returns a new array with the two combined.
Example
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
arr3 = np.append(arr1, arr2)
print(arr3)
Output example
[1 2 3 4 5 6]
The code above imports the Numpy library, then creates two arrays, arr1 and arr2, and assigns them values. The append() function is then used to combine the two arrays, with arr1 as the first parameter and arr2 as the second. The append() function returns a new array, arr3, which is printed out.
Parts of the code:
import numpy as np: imports the Numpy libraryarr1 = np.array([1, 2, 3]): creates an array calledarr1and assigns it the values 1, 2, and 3arr2 = np.array([4, 5, 6]): creates an array calledarr2and assigns it the values 4, 5, and 6arr3 = np.array.append(arr1, arr2): uses theappend()function to combinearr1andarr2into a new array calledarr3print(arr3): prints out the contents ofarr3
Helpful links
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How do I create a zero matrix using Python and Numpy?
- How do I use Scipy zeros in Python?
- How can I use Python Scipy to zoom in on an image?
- How can I use Python and Numpy to parse XML data?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How do I use Python Scipy to generate a PDF?
- How do I use Python and SciPy to create a tutorial PDF?
- How can I use Python and Numpy to zip files?
- How do I calculate the cross-correlation of two arrays using Python and NumPy?
See more codes...