Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Let's dive into numpy world
import numpy as np
arr1=list(range(1000000))
arr2=list(range(1000000,2000000))
#numpy
arr1_np = np.array(arr1)
arr2_np = np.array(arr2)
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.
Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)
%%time
res=0
for a,b in zip(arr1,arr2):
res+=(a*b)
res
CPU times: user 316 ms, sys: 27.9 ms, total: 343 ms
Wall time: 433 ms
833332333333500000
%%time
np.dot(arr1_np,arr2_np)
CPU times: user 2.19 ms, sys: 1.29 ms, total: 3.48 ms
Wall time: 16.2 ms
833332333333500000