Earn 20 XP


Adding an Element

  • Create a NumPy array:

    image.png

  • You can use append method to add an element in a NumPy array:

    image.png

  • You can also add an element to a Python list using np.append() method. But the returned object is a NumPy array.

    image.png

  • 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:

image.png

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

image.png

Removing an Element

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

image.png

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

image.png

Sorting an Array

  • You can quickly sort an array in ascending order as:

image.png

  • 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.

This website uses cookies to ensure you get the best experience. Learn more