On Wed, Aug 12, 2009 at 10:01 AM, Sandro Tosi <mo...@debian.org> wrote:
> On Wed, Aug 12, 2009 at 16:56, per freem<perfr...@gmail.com> wrote:
> > hi all,
> >
> > i have tab-separated text files that i would like to parse into arrays
> > in numpy/scipy. i simply want to be able to read in the data into an
>
> numpy's loadtxt()
With numpy 1.3 and newer, there's also numpy.genfromtxt (which actually
should behave very similar to mlab.csv2rec):
import numpy as np
from StringIO import StringIO
data = StringIO("""
#gender age weight
M 21 72.100000
F 35 58.330000
M 33 21.99
""")
arr = np.genfromtxt(data, names=True, dtype=None)
print arr['gender']
print arr['age']
Writing this back out to a file in the same format will require a bit more
of manual (though) straightforward work. There's no simple method that will
do it for you. The best one liner here is:
arr.tofile('test.txt', sep='\n')
>cat arr.txt
('M', 21, 72.099999999999994)
('F', 35, 58.329999999999998)
('M', 33, 21.989999999999998)
That should get you going. If it's not enough, feel free to post a sample
of your data file (or a representative example) and I can try to point you
further in the right direction.
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users