Skip to content
Learn Netverks

Lesson

Step 20/36 56% through track

transpose-views

Transpose and views

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

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

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

You will apply Transpose and views 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.

T or transpose() swaps axes. Transposes often return views—same memory, different strides—so writes through transposed arrays affect the original.

2D transpose

import numpy as np
a = np.arange(6).reshape(2, 3)
print(a.T)
print(a.T.shape)

Higher dimensions

arr.transpose(2, 0, 1) reorders axes explicitly—common in image batches (NHWC ↔ NCHW).

View detection

import numpy as np
a = np.arange(4)
b = a.reshape(2, 2)
c = b.T
c[0, 0] = 999
print(a)  # mutated

Important interview questions and answers

  1. Q: T vs transpose?
    A: Property .T is shorthand; transpose() accepts axis tuple for nD.
  2. Q: When is transpose a copy?
    A: When memory layout requires non-contiguous reorder that can't be strided as view.

Self-check

  1. Transpose a 3×4 matrix—new shape?
  2. Why can transposed view mutate original?

Tip: Check np.shares_memory when unsure about aliasing.

Interview prep

T effect?

Swaps rows and columns—often a view.

Mutation risk?

Editing transpose can change original array.

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

  • T vs transpose?
  • View mutation?

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