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 pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro