NumPy - Fundamentals
The code below aims to compare performance of sum on a Python list and a NumPy array:
But the output shows the NumPy sum is slower. What is a possible reason?
import numpy as np import time lst = list(range(1000000)) arr = np.array(lst) start = time.time() sum_lst = sum(lst) end = time.time() print(end - start) start = time.time() sum_arr = np.sum(arr) end = time.time() print(end - start)
But the output shows the NumPy sum is slower. What is a possible reason?
