I've been playing with python arrays for a while, But recently I faced with a weird problem. Here's my code:
import numpy as np
myarr = [
["s"],
["s"],
["w"],
["p"],
["m"],
["g"],
["c"]
]
newarr = list(myarr)
print(id(myarr))
print(id(newarr))
print(myarr, "myarr")
print(newarr, "newarr")
print("##### starting manipulation #########")
for i in newarr:
i[0] = "a"
print(myarr, "myarr")
print(newarr, "newarr")
My problem is even when I copy the "myarr" array into a new array called "newarr", when I make some changes in the "myarr", or the "newarr", both of them act like referenced arrays (referencing to the same memory address), even though they have different memory id.
I tried it with slicing, or even arr.copy() method, but they both didn't work.
I only can fix it when I use numpy array.
newarr = np.array(myarr)
Where is my problem?
Thank you in advance:)