[SciPy-User] Ignore characters while reading text
Fri Jun 14 07:46:22 CDT 2013
On 14 June 2013 14:32, Matt Newville <email@example.com> wrote:
> Would this do?
> import numpy as np
> from cStringIO import StringIO
> txt= '1 (2 3 4) (5 6 7) (8 9 10)'
> np.loadtxt(StringIO(txt.replace('(', '').replace(')', '')))
If I am not mistaken, then you are reading the data twice or thrice.
If this is big, and performance is critical, you may be better off
doing the loadtxt yourself. The core of np.loadtxt is essencially a
"from line in file: data.append(parse(line))", with some wrapping
intelligence, that probably is not needed in your case.
More information about the SciPy-User