Data slicing, mask indexing, does this trap ever bother you?
Algorithm channel https://mp.weixin.qq.com/s/AbRgqFSyMR_4zvadYQxmBA
Wechat account alg-channel
Function introduction now a well-known Internet company, likes to share, has pushed more than 160 practical information articles, combined with examples and work to explain algorithms, including: basic algorithms, examples of machine learning algorithms, introduction to deep learning, Stanford NLP course notes, Python, Pandas practice introduction series, Sina and other machine learning job interview experience.
Today, when preprocessing input data, we encounter a problem that seems strange at first glance. Let's start with the question. I want to extract part of the data according to the conditions and modify the value of a column of this part of the data. I originally thought that doing so would modify the data source. As it turns out, no!
This? Modify the data slice, will modify the original data ah! Isn't the data extracted according to the mask a reference to the original data?
It was confirmed after the experiment just now: it is different!
Modify the data slice, the original data is modified, because the slice is a reference to the original data; modify the data extracted by the mask, the original data does not change, because the data returned by the mask points to a new memory, not the original block reference!
I wonder if readers have encountered this problem? I hope I don't get involved in this pit in the future!