numpy数组及处理:效率对比
a=list(range(10)) b=list(range(0,50,5)) c=[] for i in range(len(a)): c.append(a[i]**2+b[i]**3) 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 nySum(n): a=numpy.arange(n) b=numpy.arange(n) c=a**2+b**3 return (c) from datetime import datetime print(nySum(10)) from datetime import datetime start=datetime.now() pySum(100000) timeddelta=datetime.now()-start print(timeddelta) start=datetime.now() nySum(100000) timeddelta=datetime.now()-start print(timeddelta)
![](https://img2018.cnblogs.com/blog/1482929/201809/1482929-20180929115507343-758415601.png)