Learn Before
Concept
Python Memory Allocation on Reassignment
In Python, standard operations like Y = Y + X do not update the variable Y in-place. Instead, Python first evaluates the expression Y + X, allocates new memory to host the resulting values, and then dereferences the tensor that Y used to point to, updating Y to point to this newly allocated memory location.
0
1
Updated 2026-05-01
Tags
D2L
Dive into Deep Learning @ D2L