2018.09.29 作業五
阿新 • • 發佈:2018-10-02
app com 分享 pen 列表 src 循環 del 技術分享
#a1,a2,a3 ,·····,an
#b1,b2,b3 ,·····,bn
#求:
#a1+b1,a2+b2,a3 +b3,·····+an+bn
#1、列表+循環 實現,並包裝成一個函數
def pySum(n): 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) return(c) print(pySum(10)) import numpy def npSum(n): a = numpy.arange(10) b = numpy.arange(0, 50, 5) c = a + b 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)
運行結果:
2018.09.29 作業五