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 232 views
1 answer 240 views
240 views asked Dec 25, 2016 by avibootz
1 answer 195 views
1 answer 200 views
1 answer 212 views
212 views asked Dec 17, 2016 by avibootz
...