How to copy array correctly? 2 methods give different outputs. I can't understand the logic behind it. What I wanted to achieve was the first one. Remove the repeating ones once the event occurs think it as time series. How is assigning predefined array differs from initializing new one?
myarray = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
duparray = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
for i in range(0, len(myarray)):
if myarray[i] == myarray[i-1] and myarray[i] == 1:
duparray[i] = 0
print(duparray)
OUTPUT: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
myarray = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
duparray = myarray
for i in range(0, len(myarray)):
if myarray[i] == myarray[i-1] and myarray[i] == 1:
duparray[i] = 0
print(duparray)
OUTPUT: [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1]