python - Multiplication between 2 lists -


i have 2 lists

a=[[2,3,5],[3,6,2],[1,3,2]] b=[4,2,1] 

i want output be:

c=[[8,12,20],[6,12,4],[1,3,2]] 

at present using following code problem computation time high number of values in list large.the first list of list has 1000 list in each list has 10000 values , second list has 1000 values.therefore computation time problem.i want new idea in computation time less.the present code is:

a=[[2,3,5],[3,6,2],[1,3,2]] b=[4,2,1] c=[] s=0 in b:     c1=[]     t=0     s=s+1     j in a:         t=t+1         k in j:             if t==s:                 m=i*k                 c1.append(m)     c.append(c1) print(c) 

use zip() combine each list:

a=[[2,3,5],[3,6,2],[1,3,2]] b=[4,2,1]  [[m*n n in second] m, second in zip(b,a)] 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -