From: Bill B. <wb...@gm...> - 2006-05-11 23:28:32
|
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 things like >>> numpy.matrix("[1 2; 2 3;3 4]") matrix([[1, 2], [2, 3], [3, 4]]) On the other hand since it's 'matrix', it turns things like "1 2 3" into [[1,2,3]] instead of just [1,2,3]. I think an array version of the matrix string constructor that returns the latter would be handy. But it's admittedly a pretty minor thing. ---bb On 5/12/06, Christopher Barker <Chr...@no...> wrote: > > > Bill Baxter wrote: > > Two quick questions: > > ---------1------------ > > Is there any better way to intialize an array from a string than this: > > > > A =3D asarray(matrix("1 2 3")) > > How about: > > >>> import numpy as N > >>> N.fromstring("1 2 3", sep =3D " ") > array([1, 2, 3]) > > or > > >>> N.fromstring("1 2 3", dtype =3D N.Float, sep =3D " ") > array([ 1., 2., 3.]) > > If you pass a non-empty "sep" parameter, it parses the string, rather > than treating is as binary data. fromfile works this way too -- thanks > Travis! > > -Chris > > > -- > Christopher Barker, Ph.D. > Oceanographer > > NOAA/OR&R/HAZMAT (206) 526-6959 voice > 7600 Sand Point Way NE (206) 526-6329 fax > Seattle, WA 98115 (206) 526-6317 main reception > > Chr...@no... > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > --=20 William V. Baxter III OLM Digital Kono Dens Building Rm 302 1-8-8 Wakabayashi Setagaya-ku Tokyo, Japan 154-0023 +81 (3) 3422-3380 |