--- aliases: - /2010/03/using-numpy-dtype-with-loadtxt categories: - linux - python date: 2010-03-03 22:49 layout: post slug: using-numpy-dtype-with-loadtxt title: using numpy dtype with loadtxt ---
Let's say you want to read a text file like this:
#filename start end
fdsafda.fits 23143214 23143214
safdsafafds.fits 21423 23423432
dt=np.dtype({'names':['filename','start','end'],'formats':['S100',np.float,np.float]})
[I tried also using np.str instead of S100 without success, anyone knows why?]
a = np.loadtxt(open('yourfile.txt'),dtype=dt)
('dsafsadfsadf.fits', 1.6287776249537126e+18, 1.6290301584937428e+18)
a['start']