Causes of problems
In python, numpy defaults to a shallow copy, which means that it copies the memory address of the object, resulting in two data structures sharing a single memory address. The result is that when you change the value of the copy, the original object will also change, as shown in the code:
a = (3) print(a) b = a print(b) b[0] = 10 print(b) print(a)
The output is:
[0 1 2]
[0 1 2]
[10 1 2]
[10 1 2]
prescription
Actually numpy has a solution for us, just use the copy method:
()
The data above is also shown as an example:
a = (3) print(a) b = () print(b) b[0] = 10 print(b) print(a)
The output is:
[0 1 2]
[0 1 2]
[10 1 2]
[0 1 2]
The requirement of modifying only one data structure is met!
to this article on the numpy array copy address caused by the synchronization of the replacement of the article is introduced to this, more related numpy array copy synchronization of the replacement of content, please search for my previous articles or continue to browse the following articles hope that you will support me in the future more!