Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Integer Array Indexing | Indexing and Slicing
Ultimate NumPy

Integer Array IndexingInteger Array Indexing

Apart from basic indexing, where we use an integer for a single index, NumPy also allows us to use an entire 1D array of integers (a list of integers is also possible) for indexing. There's nothing complicated about it.

Each element of the integer array used for indexing is treated as an index, so, for example, array[[0, 1, 3]] retrieves elements at indices 0, 1, and 3 in the form of a 1D array, given that array is a 1D array itself. You can also use NumPy arrays for indexing, but it makes the code more cumbersome.

Let's look at an example:

Here is an illustration to make things clear:

1D array integer array indexing

Завдання

You are managing a list of daily temperatures recorded over a week, stored in a 1D NumPy array where each element represents the temperature of a specific day. Use integer array indexing (a Python list) to retrieve the temperatures of the first day, the second day, and the last day of the week from weekly_temperatures (use a negative index only for the last element).

Все було зрозуміло?

Секція 2. Розділ 5
toggle bottom row
course content

Зміст курсу

Ultimate NumPy

Integer Array IndexingInteger Array Indexing

Apart from basic indexing, where we use an integer for a single index, NumPy also allows us to use an entire 1D array of integers (a list of integers is also possible) for indexing. There's nothing complicated about it.

Each element of the integer array used for indexing is treated as an index, so, for example, array[[0, 1, 3]] retrieves elements at indices 0, 1, and 3 in the form of a 1D array, given that array is a 1D array itself. You can also use NumPy arrays for indexing, but it makes the code more cumbersome.

Let's look at an example:

Here is an illustration to make things clear:

1D array integer array indexing

Завдання

You are managing a list of daily temperatures recorded over a week, stored in a 1D NumPy array where each element represents the temperature of a specific day. Use integer array indexing (a Python list) to retrieve the temperatures of the first day, the second day, and the last day of the week from weekly_temperatures (use a negative index only for the last element).

Все було зрозуміло?

Секція 2. Розділ 5
toggle bottom row
some-alt