๐Ÿš€ Languege/Python

python - numpy(12) ๋ฐฑํ„ฐํ™” ์—ฐ์‚ฐ

mini_world 2020. 3. 30. 18:57
๋ชฉ์ฐจ ์ ‘๊ธฐ

 

๋ฐฑํ„ฐํ™” ์—ฐ์‚ฐ ์†๋„ ์ธก์ •!

 

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