[Numpy-discussion] Creating small arrays from strings and concatenating with empty arrays

Bill Baxter wbaxter at gmail.com
Thu May 11 16:29:03 EDT 2006


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 <Chris.Barker at noaa.gov> wrote:
>
>
> Bill Baxter wrote:
> > Two quick questions:
> > ---------1------------
> > Is there any better way to intialize an array from a string than this:
> >
> >    A = asarray(matrix("1 2 3"))
>
> How about:
>
> >>> import numpy as N
> >>> N.fromstring("1 2 3", sep = " ")
> array([1, 2, 3])
>
> or
>
> >>> N.fromstring("1 2 3", dtype = N.Float, sep = " ")
> 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
>
> Chris.Barker at noaa.gov
>
>
> -------------------------------------------------------
> 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 Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>



-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060511/e6e16a33/attachment.html>


More information about the NumPy-Discussion mailing list