Explain the use of slicing and indexing with NumPy arrays, including basic vs. advanced indexing.

Quick Overview

Asks how basic slicing and advanced indexing work on NumPy arrays, including integer-array and boolean-mask selection. It tests whether you know which operations return views and which return copies, and how that affects assignment and chained indexing.

Explain the use of slicing and indexing with NumPy arrays, including basic vs. advanced indexing.

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Explain the use of slicing and indexing with NumPy arrays, including basic vs. advanced indexing. ```hint Follow the memory For each kind of index, ask whether NumPy can describe the result as the same data buffer with a new shape and strides, or whether it has to gather elements into new memory. ``` ### What a Strong Answer Covers - The forms basic indexing takes (integers, slices, `None`, `...`) and how a comma-separated tuple indexes several axes - Integer-array and boolean-mask indexing, including the shape of the result - Which operations return a view and which return a copy, and how to check - How assigning through an index differs from reading through one, including chained indexing ### Follow-up Questions - What does `M[[0, 1], [1, 2]]` return for a 2D array `M`, and how would you select the 2 by 2 block of rows 0 and 1 and columns 1 and 2? - Why does `a[[1, 2]][0] = 99` leave `a` unchanged while `a[1:3][0] = 99` changes it? - What happens when you mix a slice and an integer array in one index?

Overview: Asks how basic slicing and advanced indexing work on NumPy arrays, including integer-array and boolean-mask selection. It tests whether you know which operations return views and which return copies, and how that affects assignment and chained indexing.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Explain the use of slicing and indexing with NumPy arrays, including basic vs. advanced indexing.

What a Strong Answer Covers Guidance

  • The forms basic indexing takes (integers, slices, None , ... ) and how a comma-separated tuple indexes several axes
  • Integer-array and boolean-mask indexing, including the shape of the result
  • Which operations return a view and which return a copy, and how to check
  • How assigning through an index differs from reading through one, including chained indexing

Follow-up Questions Guidance

  • What does M[[0, 1], [1, 2]] return for a 2D array M , and how would you select the 2 by 2 block of rows 0 and 1 and columns 1 and 2?
  • Why does a[[1, 2]][0] = 99 leave a unchanged while a[1:3][0] = 99 changes it?
  • What happens when you mix a slice and an integer array in one index?