NumPy笔记:numpy与python原生数组计算效率比较
import numpy as np import random import time a = [] for i in range(10000000): a.append(random.random()) # list t1 = time.time() sum1 = sum(a) t2 = time.time() print("time_list:", (t2-t1)) # numpy b = np.array(a) t3 = time.time() sum2 = np.sum(b) t4 = time.time() print("time_numpy:", t4-t3)
time_list: 0.07811212539672852
time_numpy: 0.015620231628417969