I have two lists, one is named as A, another is named as B. Each element in A is a triple, and each element in B is just an number. I would like to calculate the result defi
This might be repeated solution, however:
>>> u = [(1, 2, 3), (4, 5, 6)] >>> v = [3, 7]
In plain Python:
Python
>>> sum([x*y for (x, *x2), y in zip(u,v)]) 31
Or using numpy (as described in user57368's answer) :
numpy
import numpy as np >>> np.dot(np.array(u)[:,0], v) 31