when comparing this two ways of doing the same thing:
import numpy as np
import time
start_time = time.time()
for j in range(1000):
bv=np.loadtxt('file%d.dat' % (j+1))
if(j%100==0):
print bv[300,0]
T1=time.time() - start_time
print("--- %s seconds ---" % T1)
and
import numpy as np
import time
start_time = time.time()
for j in range(1000):
a=open('file%d.dat' % (j+1),'r')
b=a.readlines()
a.close()
for i in range(len(b)):
b[i]=b[i].strip("\n")
b[i]=b[i].split("\t")
b[i]=map(float,b[i])
bv=np.asarray(b)
if(j%100==0):
print bv[300,0]
T1=time.time() - start_time
print("--- %s seconds ---" % T1)
I have noticed that the second one is way faster. Is there any way to have something as concise as the first method and as fast as the second one? Why is loadtxt so slow with respect to performing the same task manually?