๋ชฉ์ฐจ
์ ๊ธฐ
๋ฐฑํฐํ ์ฐ์ฐ ์๋ ์ธก์ !
import numpy as np
x = np.arange(1, 10001)
y = np.arange(10001,20001)
z = np.zeros_like(x)
for i in range(10000):
z[i] = x[1]+y[i]
print(z)
z=x+y
print(z)
# ==================================
# ์๋ ์ธก์
def runTime1():
import timeit
start = timeit.default_timer()
for i in range(10000):
z[i] = x[1] + y[i]
end = timeit.default_timer()
print('sum vector:', (end-start))
def runTime2():
import timeit
start = timeit.default_timer()
z = x + y
end = timeit.default_timer()
print('vectorize:', (end-start))
runTime1()
runTime2()
[์ฝ๋ ์คํ ๊ฒฐ๊ณผ]
[10003 10004 10005 ... 20000 20001 20002]
[10002 10004 10006 ... 29996 29998 30000]
sum vector: 0.005121769999999998
vectorize: 3.2527000000004413e-05
๊ทธ๋์.. ๋ฐฑํฐํ์ฐ์ฐ์ด ๋ ๋น ๋ฅด๋ค!
728x90