From the course: Python Data Analysis

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Indexing NumPy arrays

Indexing NumPy arrays - Python Tutorial

From the course: Python Data Analysis

Indexing NumPy arrays

- [Instructor] Let's see how we can access individual elements and ranges of elements in NumPy. We will demonstrate on our good old friend Mona Lisa. So I will start by loading that array. This is a three dimensional NumPy array with dimensions that correspond to height 1,198 pixels with 804 pixels and color, the red, green, and blue components. The syntax to get an individual pixel is just an extension of Python list indexing, except that we include multiple indices among brackets. For instance, a point roughly in the middle would be on row 600 and column 400, and we'll grab the red component. Since version two of NumPy, the D type of the element is displayed explicitly. Here, it's an eight bit integer. It's usually possible to use these values interchangeably with Python objects. Should you want to convert the NumPy number to a standard python object, you can do it with the constructor's int and float. Back to the picture. If we wish to look at pixels at the bottom right corner, we…

Contents