A Complete Step-by-Step Guide to NumPy Array Indexing and Slicing

NumPy for Data Science — Part 2

Rukshan Pramoditha
Data Science 365

--

This is the 2nd tutorial of the NumPy series. Here, I’ll discuss the following topics with examples.

Topics discussing

  • Definitions of Indexing and Slicing
  • 1D, 2D and 3D Array Indexing and Slicing
  • Boolean-Valued Indexing
  • The Mutability of an Array
  • Copies and References of a NumPy Slice
  • The IndexError

Prerequisites

You should be familiar with the basics of the Python programming language and its object-oriented programming (OOP) concepts. In addition to that, it is recommended to have knowledge in NumPy basics and array creation methods.

Introduction to Indexing and Slicing

Indexing and slicing can be used to access the elements of NumPy arrays. Indexing can be done using the location of array elements. It uses the square bracket [ ] notation. It begins with 0 like other indexing of Python objects.

Slicing can be done by combining multiple indexing techniques. It uses the : notation. It is used to select a part of a range of NumPy arrays.

--

--

Rukshan Pramoditha
Data Science 365

3,000,000+ Views | BSc in Stats | Top 50 Data Science, AI/ML Technical Writer on Medium | Data Science Masterclass: https://datasciencemasterclass.substack.com