From the course: Python Data Analysis

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Indexing NumPy arrays

Indexing NumPy arrays - Python Tutorial

From the course: Python Data Analysis

Start my 1-month free trial

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 let me load up the file. I remind you, this is a three-dimensional NumPy array with dimensions that correspond to height 1198 pixels with 804, and color three, for red, green and blue. Imgshow shows us the picture. The syntax to get that individual pixels is just an extension of Python list indexing, except that we can now include multiple indices among brackets. For instance, a point roughly in the middle would be on row 600, column 400 and we grabbed the red component. If we wish to go to the bottom right corner, we may count back from the boundary of the array, just that we would do for a list. This should be the same as 1148, 754 and one. If we try to index elements beyond the boundary, we get an index error. And of course, we can use indexing to assign values…

Contents