What is faster a list or a numpy array for creation with for loop in Python

1 Answer

0 votes
from time import process_time
import numpy as np

start = process_time()
lst = [i for i in range(10000)]
end = process_time()
print(end - start)

start = process_time()
arr = np.array([i for i in range(10000)])
end = process_time()
print(end - start)

 
 
 
 
'''
run:

0.0005832090000000012
0.0015905099999999894

'''

 



answered Mar 3, 2023 by avibootz

Related questions

2 answers 209 views
1 answer 222 views
222 views asked Dec 25, 2016 by avibootz
1 answer 174 views
1 answer 193 views
1 answer 201 views
201 views asked Dec 17, 2016 by avibootz
...