1. 程式人生 > >NUMPY數組及處理:效率對

NUMPY數組及處理:效率對

now() mage sta sat list str cal start arange

import time


print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))


print (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))


a = "Sat Mar 28 22:24:24 2016"
print (time.mktime(time.strptime(a ,"%a %b %d %H:%M:%S %Y")))

技術分享圖片

stat = "{0:%Y}年{0:%m}月{0:%d}日星期{0:%w} {0:%H}時{0:%M}分{0:%S}秒".format(datetime.now())
end = datetime.strptime(‘2018-10-25 22:00‘,"%Y-%m-%d %H:%M")
print(datetime.now()-end)


#用列表+循環實現,並包裝成函數
def Godo(n):
    a = list(range(10))
    b = list(range(0,n*5,5))
    c = []
    for i in range(len(a)):
        c.append(a[i]**2+b[i]**3)
    return (c)
print(Godo(10))


#用numpy實現,並包裝成函數
import numpy
def Godo(n):
    a = numpy.arange(10)
    b = numpy.arange(0,50, 5)
    c = a + b
    
return(c) print(Godo(10)) from datetime import datetime start = datetime.now() Godo(100000) delta = datetime.now()-start print(delta) start = datetime.now() Godo(100000) delta = datetime.now()-start print(delta)

技術分享圖片

NUMPY數組及處理:效率對