Introducing NumPy, Part 2: Indexing Arrays

-

Quick Success Data Science

Slicing and dicing like a professional

A cartoon of a happy Rubik’s cube, representing an ndarray, shedding lots of little cubes.
Indexing an array by DALL-E3

NumPy is Python’s foundational library for numerical calculations. With NumPy, the heavy lifting is handled by arrays, essentially tables of elements of the identical data type. Arrays are optimized for performance, permitting faster mathematical and logical operations than traditional Python data types, like lists.

In Part 1, we covered learn how to create arrays, describe them, and access their attributes using dot notation. In this text, we’ll examine learn how to access the weather in arrays using indexes and slices, so you may extract the worth of elements and alter them using task statements. Array indexing uses square brackets [], similar to Python lists.

As a refresher from Part 1, here’s a graphical representation of a 1D, 2D, and 3D array, with the axes annotated. You’ll need to grasp the axes’ directions to index properly.

Diagram showing graphic examples of a 1D NumPy array (as a sequence of numbers), a 2D array (as a table of numbers), and a 3D array (as a cube of numbers).
Graphical representation of 1D, 2D, and 3D arrays (from Python Tools for Scientists) (This and several other future links to my book are affiliate links)
ASK ANA

What are your thoughts on this topic?
Let us know in the comments below.

0 0 votes
Article Rating
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Share this article

Recent posts

0
Would love your thoughts, please comment.x
()
x