I have a function where I am updating the numpy array in each iteration but the original array is not updating after first iteration.
W = np.empty((3,3))
W.fill(1.0/3)
H = np.empty((2,3))
H.fill(1.0/3)
# file.txt contains 100 rows of x,y,z (with different values)
def UpdateHz(a,b,c) :
return np.subtract(H[b,:],H[c,:])
def UpdateHy(a,b,c) :
return np.subtract(W[b,:],H[c,:])
def UpdateHz(a,b,c) :
return np.subtract(W[a,:],H[b,:])
with open('file.txt') as f:
for line in f:
x,y,z = [int(s) for s in line.split()]
W[x,:] = UpdateW(x,y,z)
H[y,:] = UpdateHy(x,y,z)
H[z,:] = UpdateHz(x,y,z)
here the update function will return the updated rows for W and H. I need to update only xth row in P and Yth and zth row in H. This will keep running until the end of file.
I tried like this too :
W[x] = UpdateW(x,y,z)
H[y] = UpdateHy(x,y,z)
H[z] = UpdateHz(x,y,z)
But after first iteration the W, H holds the old values (which was initialized), What I am doing wrong here??