[SciPy-user] read ascii data
Thu Dec 13 04:20:57 CST 2007
Probably you restrict yourself to read only certain rows of your ascii
file because of performance issues... If this is not the case you might
want to ignore this Email!
Note, that if these lines are at the very end of your ascii-file you don't
gain much speed, because there's no line end in an ascii-file (most of the
file has to be read anyway). So if you know the size of your array,
depending on what you want to do it's maybe faster to read in the whole
ascii-file as one single string and then selecting the lines you want
using split(). i.e.:
LIST=[float(D) for D in FILE.read().split()]
It is simple, but very fast! However I suggest to store your data in
binary format, it's actually very simple handling them using python.
> Hi All,
> I have a file containing ascii data related to a block-structured grid.
> I could use readtxt, but I would like to have the possibility to read only
> a certain range of rows out of the file. Lets say I have ten blocks in my
> and each block 10 rows of data.
> So in one read I would like to read for instance line 30 to line 39
> I can use skip rows, but how can I limit the loadtxt to the upper limit?
> Is there something already available or do I have to do it on my own?
> Thanks in advance,
> SciPy-user mailing list
More information about the SciPy-user