seniorPyTorch

What is the difference between contiguous and non-contiguous tensors?

Updated May 17, 2026

Short answer

Contiguous tensors store elements in a single continuous memory block; non-contiguous tensors do not.

Deep explanation

Operations like transpose or permute create non-contiguous views using different strides. Some operations require contiguous memory and thus need .contiguous() which copies data into a new memory layout.

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 PyTorch interview questions

View all →