I want to update only 1 element in the 1d array and then start over fresh. if viewed as a matrix form I just want entries i = j to be changed.
my code so far:
import numpy as np
a = np.array([10, 20, 30, 40, 50])
for i, j in enumerate(a):
b = a
b[i] = j + 1
print(b)
I want each iteration of the for loop to only change one element and keep everything else the same.
the output I want looks like this:
[11, 20, 30, 40, 50]
[10, 21, 30, 40, 50]
[10, 20, 31, 40, 50]
[10, 20, 30, 41, 50]
[10, 20, 30, 40, 51]
but I'm getting this because b is not resetting even though I am (or at lest i think) restoring the original array at the start of each loop.
[11, 20, 30, 40, 50]
[11, 21, 30, 40, 50]
[11, 21, 31, 40, 50]
[11, 21, 31, 41, 50]
[11, 21, 31, 41, 51]
any ideas where I went wrong? TIA
b=awithb=a.copy()