From: Bill B. <wb...@gm...> - 2006-05-16 01:00:30
|
On 5/13/06, Charles R Harris <cha...@gm...> wrote: > > > > On 5/11/06, Bill Baxter <wb...@gm...> wrote: > > > > Ahh, I hadn't noticed the fromstring/fromfile methods. > > > > Hmm. That seems ok for making a row-at-a-time, but it doesn't support > > the full syntax of the matrix string constructor, which allows for thi= ngs > > like > > > > >>> numpy.matrix("[1 2; 2 3;3 4]") > > matrix([[1, 2], > > [2, 3], > > [3, 4]]) > > > > You can reshape the array returned by fromstring, i.e., > > In [6]: fromstring("1 2 2 3 3 4", sep=3D" ").reshape(-1,2) > Out[6]: > array([[1, 2], > [2, 3], > [3, 4]]) > But if the string comes from someplace other than a literal right there in the code (like loaded from a file or passed in as an argument or something)= , I may not know the shape in advance. I'll just stick with the matrix constructor, since for my case, I do know the array dim is 2. --bill |