From: Charles R H. <cha...@gm...> - 2006-11-08 14:55:53
|
On 11/8/06, Francesc Altet <fa...@ca...> wrote: > > A Dimecres 08 Novembre 2006 13:42, amit soni escrigu=E9: > > Hi, > > i have a file with following format: > > 1 2 > > 3 9 > > 2 3 > > 4 4 > > I want to read it and then store the values into two matrices, s.t. > > A=3D[1 2;3 9] > > B=3D[2 3;4 4] > > > > Can anyone tell me how to do this in python? > > thanks > > Amit Try In [8]: tmp =3D fromfile('tmp.txt', sep=3D' ', dtype=3Dint) In [9]: a =3D tmp[:4].reshape(2,2) In [10]: b =3D tmp[4:].reshape(2,2) In [11]: a Out[11]: array([[1, 2], [3, 9]]) In [12]: b Out[12]: array([[2, 3], [4, 4]]) Chuck |