Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

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 170 views
1 answer 182 views
182 views asked Dec 25, 2016 by avibootz
1 answer 129 views
129 views asked Nov 23, 2020 by avibootz
1 answer 146 views
1 answer 178 views
...