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 can I use Python and SciPy to find the zeros of a function?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How do I use the scipy ttest_ind function in Python?
- How do I create a zero matrix using Python and Numpy?
- How do I create a numpy array of zeros using Python?
- How do I use Python Scipy to perform a Z test?
- How can I use Python and Numpy to parse a JSON file?
- How can I use the x.shape function in Python Numpy?
- How do I create a QQ plot using Python and SciPy?
See more codes...