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 calledarr1
and assigns it the values 1, 2, and 3arr2 = np.array([4, 5, 6])
: creates an array calledarr2
and assigns it the values 4, 5, and 6arr3 = np.array.append(arr1, arr2)
: uses theappend()
function to combinearr1
andarr2
into a new array calledarr3
print(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 can I use Python Scipy to zoom in on an image?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How can I use Python and Numpy to parse XML data?
- How do I use the NumPy transpose function in Python?
- How do I uninstall Python Scipy?
- How do I create an array of zeros with the same shape as an existing array using Python and NumPy?
- How do I use Scipy zeros in Python?
- How do I create a zero matrix using Python and Numpy?
See more codes...