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 library
- arr1 = np.array([1, 2, 3]): creates an array called- arr1and assigns it the values 1, 2, and 3
- arr2 = np.array([4, 5, 6]): creates an array called- arr2and assigns it the values 4, 5, and 6
- arr3 = np.array.append(arr1, arr2): uses the- append()function to combine- arr1and- arr2into a new array called- arr3
- print(arr3): prints out the contents of- arr3
Helpful links
More of Python Scipy
- How do I uninstall Python Scipy?
- How do I create a 2D array of zeros 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 do I use the scipy ttest_ind function in Python?
- How can I use Python and Numpy to zip files?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How can I use Python SciPy to fit a model?
- How can I use Python and SciPy to find the zeros of a function?
- How can I use Python and Numpy to parse XML data?
See more codes...