dimanche 18 novembre 2018

How do I replace a value in a matrix which corresponding to another matrix?

For example

a = ['1', '2', '3', '4', '5', '6']
b = [[(1, 0.5), (2, 0.8)], [(4, 0.11), (6, 0.23)]]

And I want to get a matrix c:

c = [0.5, 0.8, 0, 0.11, 0, 0]

That's like if the i in a = ww for ww,ee in n for n in b, then replace with ee else 0

I try some if and else command and here is my code

for n in b:
for t,y in n:
    for tt in a:
        mmm = [y if t == ''.join(tt) else ''.join(tt)]
        print(mmm)

But it failed. How should I code for this situation?

Aucun commentaire:

Enregistrer un commentaire