[Numpy-discussion] Reading footer lines
Stéfan van der Walt
Tue Aug 13 08:00:36 CDT 2013
On Tue, Aug 13, 2013 at 2:20 PM, Resmi <email@example.com> wrote:
> I've a list of long files of numerical data ending with footer lines
> (beginning with #). I am using numpy.loadtxt to read the numbers, and
> loadtxt ignores these footer lines. I want the numpy code to read one of the
> footer lines and extract words from it. Is there a way to use loadtxt for
> this? If there weren't many files I could have used the line number (which
> keep varying between the files) of the footer line along with linecache.
> Nevertheless there should be a generic way to do this in numpy?
If the data-set is not too big, you can read it into memory with
"f.readlines()" and then do a bit of preparsing on the resulting array
before sending the rest of it to np.loadtxt (which allows an array of
strings as input).
More information about the NumPy-Discussion