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
).
JavaScript
x
9
1
error_variance_vector=[]
2
for i in range(0,len(bpm_indexes)):
3
n = 10
4
error_variance_vector.append(n)
5
6
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]
7
8
sigma_square = [i**2 for i in error_variance_vector]
9
Here’s my attempt:
JavaScript
1
7
1
w = []
2
for sigma_square1 in sigma_square:
3
w.append(error_variance_vector / sigma_square1)
4
5
W = np.diag(w)
6
print(W)
7
but I got an error message:
JavaScript
1
2
1
TypeError: unsupported operand type(s) for /: 'list' and 'int'
2
Advertisement
Answer
This should work:
JavaScript
1
2
1
w = [e/s for e,s in zip(error_variance_vector,sigma_square)]
2