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

Markus Rosenstihl markusro at element.fkp.physik.tu-darmstadt.de
Tue Jan 16 17:21:02 CST 2007


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
-------------- 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/b3c35a8d/attachment.bin 


More information about the SciPy-user mailing list