On Thu, May 12, 2011 at 12:21:46PM +0200, Claudia Chan Yone wrote: > Hi, > > I have a problem with the Numpy module, but I think it is a very basic issue > for many of you... > I have a file with numerical data (2 columns, and 5 lignes) as : > 1 2 > 3 4 > ... ... > > And I woulid like to convert it in a matrix as : > [[1,2] > [3,4] > ...] > > My python script is : > > fic=open('file.txt','r') > ligne=fic.readlines() > fic.close()
Try using the loadtxt function in numpy >>> m = numpy.loadtxt('file.txt') array([[ 1., 2.], [ 3., 4.]]) Miguel _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion