numpy数组性能

numpy学习专题

四、numpy数组性能

numpy数组的性能

import random
li = []
for i in range(10000000):
    li.append(random.random())
import time
t1 = time.time()
ret = sum(li)
t2 = time.time()
print("耗时:%f"%(t2-t1))
print(ret)
耗时:0.052087
4999862.242654033
import numpy as np
n = np.array(li)

t1 = time.time()
ret = np.sum(n)
t2 = time.time()
print("耗时:%f"%(t2-t1))
print(ret)
耗时:0.015924
4999862.242654191

一定要支持作者哦

你可能感兴趣的:(numpy,python)