#列表+循环实现,并包装成函数 import numpy def numpy(n): a = list(range(n)) b = list(range(0,10*n,5)) c = [] for i in range(len(a)): c.append(a[i]**2+b[i]**3) return (c) print(numpy(10)) #numpy实现,并包装成函数 def pySum(n): a = list(range(n)) b = list(range(0,10*n,5)) c = [] for i in range(len(a)): c.append(a[i]**2+b[i]**3) return (c) print(pySum(10)) #对比两种方法实现的效率,给定一个较大的参数n,用运行函数前后的timedelta表示 from datetime import datetime,timedelta start = datetime.now() pySum(10000) print(start + timedelta(hours=70000)) from datetime import datetime start1 = datetime.now() numpy(10000) print(start1 + timedelta(hours=70000))