[Numpy-discussion] Problem with Numpy and array

Claudia Chan Yone chanyone.claudia at gmail.com
Thu May 12 07:40:40 EDT 2011


Merci beaucoup beaucoup!!

2011/5/12 Éric Depagne <eric at depagne.org>

> Le jeudi 12 mai 2011 12:21:46, Claudia Chan Yone a écrit :
> > 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()
> >
> > m=numpy.array(ligne)
> >
> > and I get :
> > ['1,2\n' '3,4']
> >
> > So I cannot call m[0][0]...
> >
> > Even if I modify my text file with :
> > [[1,2],
> > [3,4]
> > ...]
> >
> > I get :
> >
> > ['[[1,2],[3,4]]'] and I cannot call m[0][0].
> >
> > Thank you very much for your help,
> >
> >
> > Clo
> numpy.loadtxt() is probably what you need here.
>
> hth.
>
> Éric.
> --
> Un clavier azerty en vaut deux
> ----------------------------------------------------------
> Éric Depagne                            eric at depagne.org
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110512/f436d1f6/attachment.html>


More information about the NumPy-Discussion mailing list