## NumPy Array Append

NumPy append is a function which is primarily used to add or attach an array of values to the end of the given array and usually, it is attached by mentioning the axis in which we wanted to attach the new set of values axis=0 denotes row-wise appending and axis=1 denotes the column-wise appending and any number of a sequence or array can be appended to the given array using the append function in numpy.

## Syntax:

The basic syntax of the Numpy array append function is:

numpy.append(ar, values, axis=None)

• numpy denotes the numerical python package.
• append is the keyword which denoted the append function.
• ar denotes the existing array which we wanted to append values to it.
• values are the array that we wanted to add/attach to the given array.
• axis denotes the position in which we wanted the new set of values to be appended.
• axis=0 represents the row-wise appending and axis=1 represents the column-wise appending.

## Examples of NumPy Array Append

Following are the examples as given below:

## Example #1

Let us look at a simple example to use the append function to create an array.

importnumpy as np

arr1=np.append ([12, 41, 20], [[1, 8, 5], [30, 17, 18]])

arr1

## Example #2

importnumpy as np

arr1=np.append ([[12, 41, 20], [1, 8, 5]], [[30, 17, 18]],axis=0)

arr1

## Example #3

In this example, let’s create an array and append the array using both the axis with the same similar dimensions.

```import numpy as np
arr1=np.array([[12, 41, 20], [1, 8, 5]])
print(arr1)
#### Appending Row-wise
print(np.append(arr1,[[41,80,14]],axis=0))
print('\n')
#### Appending column-wise
print(np.append(arr1,[[41,80,14],[71,15,60]],axis=1))
print('\n')
```

## Example #4

```import numpy as np
arr1 = np.arange(10)
print("one dimensional arr1 : ", arr1)
print("Shape of the array : ", arr1.shape)
arr2 = np.arange(5, 15)
print("one dimensional arr2 : ", arr2)
print("Shape of the array : ", arr2.shape)
# Array appending
arr3 = np.append(arr1, arr2)
print("Appended arr3 : ", arr3)
```

### Example #5

```import numpy as np
arr1 = np.arange(10).reshape(2, 5)
print("one dimensional arr1 : ", arr1)
print("Shape of the array : ", arr1.shape)
arr2 = np.arange(5, 15).reshape(2, 5)
print("one dimensional arr2 : ", arr2)
print("Shape of the array : ", arr2.shape)
# Array appending
arr3 = np.append(arr1, arr2)
print("Appended arr3 : ", arr3)
```

Apply now for Advanced Python Training Course