Selecting elements with a Numpy Array


Selecting elements with a Numpy Array

To select items in a Numpy array, we can use the same notation as normal python arrays. In the example below, we create an array using the special arange method. Then, we show how to select a single element, and how to select multiple elements using the python slice.

# create a numpy array from a range 0 to 11
arr = np.arange(0, 11)

# Selecting an array like a normal python array

# Using the slice notation like numpy to select 1 up to 5 (does not include 5)

# Select up to 4

# select after 3
GoTea - KoalaTea