seniorNumPy

How does NumPy handle internal memory views for reshaped tensors?

Updated May 17, 2026

Short answer

Reshape creates a view when memory layout is compatible, otherwise it creates a copy.

Deep explanation

Reshaping relies on stride reinterpretation. If the array is contiguous in memory, reshape only updates metadata like shape and strides. If the layout is non-contiguous, NumPy must allocate a new buffer and copy data to maintain logical correctness.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More NumPy interview questions

View all →