Skip to content
Learn Netverks

Lesson

Step 21/36 58% through track

stacking-splitting

Stacking and splitting

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

This lesson

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

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

You will apply Stacking and splitting 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.

Combine arrays with np.concatenate, vstack, hstack, stack, and column_stack. Split with np.split, hsplit, vsplit.

Stack along existing axis

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(np.concatenate([a, b]))

New axis stacking

  • np.stack([a, b], axis=0) — new dimension
  • np.vstack — rows on top of rows
  • np.hstack — columns beside columns
  • np.column_stack — treat 1D as columns

Splitting

import numpy as np
a = np.arange(9).reshape(3, 3)
parts = np.split(a, 3, axis=1)
print([p.shape for p in parts])

Important interview questions and answers

  1. Q: stack vs concatenate?
    A: stack creates new axis; concatenate joins along existing axis.
  2. Q: column_stack use case?
    A: Build design matrix from feature vectors.

Self-check

  1. Stack two 1D arrays as rows of 2×3 matrix.
  2. Split array into three equal parts along axis 0.

Tip: column_stack builds feature matrices from 1D vectors.

Interview prep

stack vs concat?

stack adds new axis; concatenate joins along existing axis.

vstack?

Stack arrays as 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

  • vstack vs concatenate?
  • split sections?

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