numpy数组及处理:效率对比

def pySum(n):
    a = list(range(n))
    b = list(range(0,3*n,3))
    c = []
    for i in range(len(a)):
        c.append(a[i]**2+b[i]**3)
    return c


import numpy
def nySum(n):
    a = numpy.arange(n)
    b = numpy.arange(0,3*n,3)
    c = a**2 + b**3
    return c

import datetime
start = datetime.datetime.now()
pySum(200000)
delta = print(datetime.datetime.now()-start)

start1 = datetime.datetime.now()
nySum(200000)
delta = print(datetime.datetime.now()-start1)

posted @ 2018-09-29 11:45  safufu  阅读(187)  评论(0编辑  收藏  举报