numpy数组及处理

#获取当前时间
from datetime import datetime
time=datetime.now()
print(time)

dtp=datetime.strptime('2018年9月22日9时5分5秒','%Y年%M月%d日9时5分5秒')
print(dtp) #用datetime.strip() 将字符串转时间
end=datetime.strptime("2018-10-24 5:00","%Y-%m-%d %H:%M") #时间转字符串
print(end-dtp)


 
#1.用列表+循环实现,并包装成函数
def ListSum(x):
a=list(range(x))
b=list(range(0,2*x,2))
c=[]
for i in range(len(a)):
c.append(a[i]**2+b[i]**3)
return c

#用numpy实现,并包装成函数
def npSum(y):
import numpy as np;
a=np.arange(y)
b=np.arange(0,2*y,2)
c=a**2+b**3
#对比两种方法实现的效率,给定一个较大的参数你,用运行函数前后的timedetal表示。
dt=datetime.now()
ListSum(5000)
print(datetime.now()-dt)

dt1=datetime.now()
npSum(5000)
print(datetime.now()-dt1)






猜你喜欢

转载自www.cnblogs.com/huang201606050002/p/9841764.html