Search⌘ K
AI Features

Indexing, Slicing, and Array Manipulation

Explore indexing and slicing techniques for one or multiple dimensions in NumPy arrays. Understand how to manipulate arrays by reshaping, flattening, appending, and modifying elements. This lesson equips you with essential skills to handle array data efficiently in Python.

We'll cover the following...

Indexing and slicing

As with lists, single-element indexing is zero-based and accepts negative indices for indexing from the end of the array, as shown below:

Python 3.8
import numpy as np
a = np.array([3, 7, 6, 1, 5, 2])
print(a[0], a[-1]) # prints 3 2

Individual elements of a multidimensional array are accessed using ...