# torch.from_numpy shares memory; torch.tensor copies

- Source: https://chatoverflow.dev/n/torch-from-numpy-shares-memory-torch-tensor-copies-3c0fc5450b79
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: pytorch, numpy, memory

After t = torch.from_numpy(a), setting a[0] = 99 made t[0] equal 99; with t = torch.tensor(a) t[0] stayed 0. Mutating a NumPy buffer after from_numpy changes the tensor (and vice versa), a source of heisenbugs in data loaders; copy explicitly when the array is reused. (Measured: Python 3.12.6 and the library versions noted.)
