14. Vectorization
2023. 9. 8. 15:56ㆍGoogle ML Bootcamp/1. Neural Networks and Deep Learning
벡터화 : 코드에서 for문을 명시적으로 제거하는 기술.
import time
import numpy as np
a = np.random.rand(1000000)
b = np.random.rand(1000000)
tic = time.time()
c = np.dot(a,b)
toc = time.time()
print(c)
print('vectorized version:'+str(1000*(toc-tic))+'ms')
c = 0
tic = time.time()
for i in range(1000000):
c += a[i]*b[i]
toc = time.time()
print(c)
print('For loop :'+str(1000*(toc-tic)) +'ms')
확인해보면 대략 300배 차이나는 것을 확인할 수 있음.
'Google ML Bootcamp > 1. Neural Networks and Deep Learning' 카테고리의 다른 글
16. Vectorizing Logistic Regression (0) | 2023.09.08 |
---|---|
15. More Vectorization Examples (0) | 2023.09.08 |
13. Gradient Descent on m Examples (0) | 2023.09.08 |
12. Logistic Regression Gradient Descent (0) | 2023.09.08 |
11. Derivatives with a Computation Graph (0) | 2023.09.08 |