Adding an Element
-
Create a NumPy array:
-
You can use append method to add an element in a NumPy array:
-
You can also add an element to a Python list using np.append() method. But the returned object is a NumPy array.
-
You can also add a list of elements. Try doing this by yourself. For example,
.1
np.append(arr, [11, 22])
Caution!
- A NumPy array doesn’t support append() method directly on the array. The given snippet will clear this:

- But a Python list supports append() method directly on the Python list:

Removing an Element
- You can remove an element from an array using delete method of NumPy. See the snippet below:

- You can also remove an element from a Python list using np.delete() method.

Sorting an Array
- You can quickly sort an array in ascending order as:

- You can sort a NumPy array or a Python list by using ‘.sort()’ directly on the array or the list. You can try this by yourself.