Why Your PyTorch Tensor Changes When You Edit the NumPy Array

https://hackernoon.imgix.net/images/4bfpoAFKgXWLIX7Z9FTXYpFW4XR2-u3037ua.png

Here is a situation that is easy to run into: you load your data into a NumPy array, convert it to a PyTorch tensor for training, and change a few values in the tensor. Later you print the original array and the changes are already there. You never touched the array.

Or it happens the other way around. You tweak the array, and a tensor you created earlier quietly changes. Nothing crashes and no warning appears, so the bug usually surfaces much later as strange training results.

This article explains what is actually happening, which conversions share memory and which copy, and how to control it.

Quick Summary

  • torch.from_numpy() and tensor.numpy() do not copy data. The tensor and the array share the same memory, so an edit on one side shows up on the other.
  • torch.tensor() always copies. torch.as_tensor() shares memory only when it doesn't need to change the dtype...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more

https://img.semafor.com/e241c93d506560439f6da6b04ed34a53607e1ce8-4585x3056.jpg?rect=0,325,4585,2407&w=1200&h=630&q=75&auto=format

Source: the White House's AI task force and AI companies agreed to a December 31 deadline for frontier labs to set up safety teams and engage external auditors

December 3, 2026, 8:20 PM Top News More: CISA, Reuters, NBC News, The Guardian, Binance Blog, Reuters, Bloomberg Law, Washington Post, Bloomberg, New York Post, MarketWatch, VentureBeat, The Verge, CNBC, Associated Press, Digital Trends, SiliconANGLE, Fortune, Bloomberg, The Coin Republic, NewsNation, TheStreet, The Deep View, Slate, The Block, Schneier

https://cdn.mos.cms.futurecdn.net/d5Viy9iv8ZWg8n3WJg2hRe-1920-80.jpg

‘It’s all been curated, considered, and created by a human hand, and you can’t quite believe it’ — GTA 6 dev says Leonida was designed to feel 'unique and there’s no repetition’ in the world, from every ‘puddle of bin juice’ to an ‘overgrown garden’

* Grand Theft Auto 6 Vice President of Art: Environment Adam Cochrane shares how Rockstar imitated "life" in Leonida * Cochrane says every detail, including "a puddle of bin juice around the bottom of a dumpster," was made to look unique * The developer says every detail was "