Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

fancy-indexing

Fancy indexing

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Fancy indexing: NumPy ndarray operations, vectorization, and numerical patterns used across the Python scientific stack.

Teams apply Fancy indexing in every serious NumPy project—skipping it leaves blind spots in analysis and reviews.

You will apply Fancy indexing in contexts like: Notebooks, feature engineering pipelines, and custom numerical code.

Read the narrative, run `import numpy as np` snippets in the playground (install NumPy with pip if the runner lacks it), tweak shapes and dtypes, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

Pass integer arrays as indices to select arbitrary elements or subarrays. Fancy indexing returns copies, unlike basic slicing views.

1D integer array index

import numpy as np
a = np.array([10, 20, 30, 40, 50])
idx = np.array([0, 2, 4])
print(a[idx])

2D fancy indexing

arr[rows, cols] pairs indices element-wise. Useful for extracting scattered pixels or batch-gather operations.

Combined with boolean

You can use boolean masks and integer indices in different steps—avoid mixing in one index tuple unless you understand copy semantics.

Important interview questions and answers

  1. Q: Fancy vs slice copy?
    A: Fancy indexing always copies selected elements.
  2. Q: Negative indices?
    A: Work in integer array indices same as single indexing.

Self-check

  1. Select elements at indices [1, 3, 3] from 1D array.
  2. Why does fancy indexing return a copy?

Pitfall: Fancy indexing copies—don't assume view semantics.

Interview prep

Copy?

Integer array indexing returns copy, not view.

Use case?

Gather scattered elements or reorder rows.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Integer array index?
  • Repeat rows risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump