In [1]:
from random import random
list_1 = [random() for _ in range(1000000)]
list_2 = [random() for _ in range(1000000)]
In [2]:
out = [x + y for (x, y) in zip(list_1, list_2)]
out[:3]
Out[2]:
In [3]:
%timeit [x + y for (x, y) in zip(list_1, list_2)]
Out[3]:
In [4]:
import numpy as np
arr_1 = np.array(list_1)
arr_2 = np.array(list_2)
In [5]:
type(list_1), type(arr_1)
Out[5]:
In [6]:
arr_1.shape
Out[6]:
In [7]:
arr_1.dtype
Out[7]:
In [8]:
sum_arr = arr_1 + arr_2
sum_arr[:3]
Out[8]:
In [9]:
%timeit arr_1 + arr_2
Out[9]: