[SciPy-user] Newbie: Reading a slice of a file

Chiara Caronna chiaracaronna at hotmail.com
Tue Jan 16 08:35:13 EST 2007


Thanks for your suggestion. I managed to modify the pylab.load function; I 
inserted a new optional input, skiprowsfrom=n, where n is the rows from 
which you want to skip;I think this can bu useful, for example,  if in the 
file there are not only floats, but also uncommented text. Here is my 
modification in the file mlab.py:

for i,line in enumerate(fh):
        if i<skiprows: continue
#I JUST ADDED THIS TWO LINES!
        if skiprowsfrom is not None:
           if i>=skiprowsfrom-1: continue
...
...



>From: Vincent Nijs <v-nijs at kellogg.northwestern.edu>
>Reply-To: SciPy Users List <scipy-user at scipy.org>
>To: SciPy Users List <scipy-user at scipy.org>
>Subject: Re: [SciPy-user] Newbie: Reading a slice of a file
>Date: Mon, 15 Jan 2007 12:28:50 -0600
>
>I don't think you can do that directly with pylab.load. You could do
>
>data = pylab.load(f,delimiter=',',skiprows=n-10)
>
>Where n = the length of the file.
>
>You could probably do something more flexible with the csv module. The
>following will read all your data into an array (assumes all elements are
>floats). You can add-in selection conditions as needed.
>
>import numpy
>reader = csv.reader(file('yourfile.csv','r'))
>data = numpy.array([i for i in reader])
>data = data.astype('f')
>
>Vincent
>
>
>On 1/15/07 11:51 AM, "Chiara Caronna" <chiaracaronna at hotmail.com> wrote:
>
> > I need to read just some rows of a file... do you know how to do it?
> > I found out that with pylab.load I can skip some rows from the top, but 
>I
> > don't know how to skip from the bottom... maybe there is an other 
>function?
> > Thanks
> > Chiara
> >
> >
> >> From: Darren Dale <dd55 at cornell.edu>
> >> Reply-To: SciPy Users List <scipy-user at scipy.org>
> >> To: SciPy Users List <scipy-user at scipy.org>
> >> Subject: Re: [SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5
> >> to30 places?
> >> Date: Mon, 15 Jan 2007 12:19:58 -0500
> >>
> >> On Monday 15 January 2007 11:52, Dick Moores wrote:
> >>> That's great! Thanks!
> >>>
> >>> Now, how about something such as (5/23)**(2/7)?
> >>> print repr(n.exp(n.log(5/23)*2/7))
> >>> gets ValueError: log domain error
> >>
> >> integer division 5/23=0. The log of zero is either going to give you
> >> -infinity
> >> or an error.
> >>
> >> Darren
> >> _______________________________________________
> >> SciPy-user mailing list
> >> SciPy-user at scipy.org
> >> http://projects.scipy.org/mailman/listinfo/scipy-user
> >
> > _________________________________________________________________
> > Don't just search. Find. Check out the new MSN Search!
> > http://search.msn.com/
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user at scipy.org
> > http://projects.scipy.org/mailman/listinfo/scipy-user
> >
>
>--
>Vincent R. Nijs
>Assistant Professor of Marketing
>Kellogg School of Management, Northwestern University
>2001 Sheridan Road, Evanston, IL 60208-2001
>Phone: +1-847-491-4574 Fax: +1-847-491-2498
>E-mail: v-nijs at kellogg.northwestern.edu
>Skype: vincentnijs
>
>
>
>_______________________________________________
>SciPy-user mailing list
>SciPy-user at scipy.org
>http://projects.scipy.org/mailman/listinfo/scipy-user

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/




More information about the SciPy-User mailing list