a = list(range(10)) b =list(range(0,50,5)) c=[] for i in range(len(a)): c.append (a[i] + b[i]) print(a,b,c)
运行结果
def pySum(n): a = list(range(n)) b = list(range(0,5*n,5)) c = [] for i in range(len(a)): c.append(a[i]**2+b[i]** 3) return(c) print(pySum(10)) import numpy def npSum(n): a = numpy.arange(10) b = numpy.arange(0,50,5) c = a+b print(a, b,c) return(c) print(npSum(10)) from datetime import datetime start = datetime.now() pySum(100000) delta = datetime.now()-start print(delta) start = datetime.now() npSum(100000) delta = datetime.now()-start print(delta)
运行结果