Merci beaucoup beaucoup!!<br><br><div class="gmail_quote">2011/5/12 Éric Depagne <span dir="ltr"><<a href="mailto:eric@depagne.org">eric@depagne.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Le jeudi 12 mai 2011 12:21:46, Claudia Chan Yone a écrit :<br>
<div><div></div><div class="h5">> Hi,<br>
><br>
> I have a problem with the Numpy module, but I think it is a very basic<br>
> issue for many of you...<br>
> I have a file with numerical data (2 columns, and 5 lignes) as :<br>
> 1 2<br>
> 3 4<br>
> ... ...<br>
><br>
> And I woulid like to convert it in a matrix as :<br>
> [[1,2]<br>
> [3,4]<br>
> ...]<br>
><br>
> My python script is :<br>
><br>
> fic=open('file.txt','r')<br>
> ligne=fic.readlines()<br>
> fic.close()<br>
><br>
> m=numpy.array(ligne)<br>
><br>
> and I get :<br>
> ['1,2\n' '3,4']<br>
><br>
> So I cannot call m[0][0]...<br>
><br>
> Even if I modify my text file with :<br>
> [[1,2],<br>
> [3,4]<br>
> ...]<br>
><br>
> I get :<br>
><br>
> ['[[1,2],[3,4]]'] and I cannot call m[0][0].<br>
><br>
> Thank you very much for your help,<br>
><br>
><br>
> Clo<br>
</div></div>numpy.loadtxt() is probably what you need here.<br>
<br>
hth.<br>
<br>
Éric.<br>
<font color="#888888">--<br>
Un clavier azerty en vaut deux<br>
----------------------------------------------------------<br>
Éric Depagne                            <a href="mailto:eric@depagne.org">eric@depagne.org</a><br>
</font><div><div></div><div class="h5">_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br>