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

Markus Rosenstihl markusro at element.fkp.physik.tu-darmstadt.de
Wed Jan 17 03:59:05 CST 2007


Am 17.01.2007 um 09:34 schrieb Chiara Caronna:

>
> Thank you, but the problem is that in the file from time to time there 
> are
> non numerical values, so I need to skip those rows...
>

doc(scipy.io.read_array) says the following:

scipy.io.read_array(fileobject, separator=None, columns=None, 
comment='#', lines=None, atype='d', linesep='\n', rowsize=10000, 
missing=0)

comment -- the comment character (line will be ignored even if it is
		   specified by the lines tuple)
missing -- value to insert in array when conversion to number fails.


So you could try to use one of them:

If your file looks like this

0 0 0 0 0 1
! a comment
0 0 0 0 0 2
! some more comment

you can set: comment='!'

This would skip all lines starting with "!"

Markus

>> From: Markus Rosenstihl <markusro at element.fkp.physik.tu-darmstadt.de>
>> 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: Wed, 17 Jan 2007 00:21:02 +0100
>>
>> Am 15.01.2007 um 18:51 schrieb Chiara Caronna:
>>
>>> 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
>>
>> Hi
>>
>> You can use scipy.io.read_array:
>>
>>
>> In [313]: b
>> Out[313]:
>> array([[0, 0, 0],
>>        [1, 0, 0],
>>        [2, 0, 0],
>>        [3, 0, 0],
>>        [4, 0, 0],
>>        [5, 0, 0],
>>        [6, 0, 0],
>>        [7, 0, 0],
>>        [8, 0, 0],
>>        [9, 0, 0]])
>>
>> In [314]: scipy.io.write_array('testarray',b)
>>
>> In [315]: scipy.io.read_array('testarray',lines=(1,(4,7)))
>> Out[315]:
>> array([[ 1.,  0.,  0.],
>>        [ 4.,  0.,  0.],
>>        [ 5.,  0.,  0.],
>>        [ 6.,  0.,  0.]])
>>
>> In [316]:
>>
>> HTH,
>>
>> Markus
>
>
>> << PGP.sig >>
>
>
>
>
>> _______________________________________________
>> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: Signierter Teil der Nachricht
Url : http://projects.scipy.org/pipermail/scipy-user/attachments/20070117/3348d4c1/attachment.bin 


More information about the SciPy-user mailing list