One - One Code All

Blog Content

Python两个列表里元素对应相乘,列表相除

Python   2013-01-06 16:42:12

Python两个列表里元素对应相乘,实现方法



方法一:


结合zip函数,使用map函数:


List1 = [1,2,3,4]

List2 = [5,6,7,8]

List3 = map(lambda (a,b):a*b,zip(List1,List2))

print List3


方法二:


把列表转化为数组,使用np.multiply函数


List = [1,2,3]

List2 = [5,6,7]

List3 = np.multiply(np.array(List1),np.array(List2))

print List3.tolist()



上一篇:时间序列预测法
下一篇:mysql快速插入百万数据

The minute you think of giving up, think of the reason why you held on so long.