Search⌘ K
AI Features

Indexing and Slicing

Explore how to select and modify elements in NumPy 1D and 2D arrays using indexing and slicing. Understand how to access rows, columns, and individual elements to effectively handle numerical data for analysis.

We'll cover the following...

1-D arrays (vectors)

In the simplest case, selecting one or more elements of the NumPy array works in a very similar way to Python lists. We can do the following in NumPy arrays:

  • We can grab a value using the negative index (starts with -1). We can also do the same in Python lists.

  • We can get a range from our NumPy array.

  • We can also use the negative index to grab a range from our NumPy array.

  • We can grab the values up to and from certain indexes of a NumPy array. We don’t need to give start and stop indices, since they’re optional.

Let’s create a NumPy array and grab some values ...