Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Divide a list by elements of another list

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TypeError: unsupported operand type(s) for /: 'list' and 'int'

>Solution :

This should work:

w = [e/s for e,s in zip(error_variance_vector,sigma_square)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading