我们在处理大数据的时候,尽量避免使用for循环,那样会将低速度
import numpy as np import time a = np.random.rand(1000000) b = np.random.rand(1000000) tic = time.time() z = np.dot(a,b) toc = time.time() print(z) print('向量化:'+str((toc-tic)*1000)+'ms') c = 0 for i in range(1000000): c += a[i]*b[i] top = time.time() print(c) print('非向量化:'+str((top-tic)*1000)+'ms')
249951.26378956603 向量化:1.995086669921875ms 249951.2637895705 非向量化:307.2049617767334ms
我们看到dot函数能够很快的完成任务
标签:1000000,----,print,神经网络,ms,time,np,量化 From: https://www.cnblogs.com/kk-style/p/16726561.html