Write a Numpy program to test whether numpy array is faster than Python list or not
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import time
import numpy as np
SIZE = 200000
list1 = range(SIZE)
list2 = range(SIZE)
arra1 = np.arange(SIZE)
arra2 = np.arange(SIZE)
start_list = time.time()
result=[(x,y) for x,y in zip(list1,list2)]
print("Time to aggregates elements from each of the iterables:")
print("List:")
print((time.time()-start_list)*1000)
start_array = time.time()
result = arra1 + arra2
print("NumPy array:")
print((time.time()-start_array)*1000)
Sample Output:
Time to aggregates elements from each of the iterables: List: 72.64399528503418 NumPy array: 19.61684226989746
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال