I want to divide a list error_variance_vector
by an element in another list sigma_square1
, such that it gives corresponding W
element (w_i
).
error_variance_vector=[] for i in range(0,len(bpm_indexes)): n = 10 error_variance_vector.append(n) error_variance_vector = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] sigma_square = [i**2 for i in error_variance_vector]
Here’s my attempt:
w = [] for sigma_square1 in sigma_square: w.append(error_variance_vector / sigma_square1) W = np.diag(w) print(W)
but I got an error message:
TypeError: unsupported operand type(s) for /: 'list' and 'int'
Advertisement
Answer
This should work:
w = [e/s for e,s in zip(error_variance_vector,sigma_square)]