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

Charles R Harris charlesr.harris at gmail.com
Fri May 12 17:47:30 EDT 2006


On 5/11/06, Bill Baxter <wbaxter at gmail.com> 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 things 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=" ").reshape(-1,2)
Out[6]:
array([[1, 2],
       [2, 3],
       [3, 4]])

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060512/c8adfb6a/attachment.html>


More information about the NumPy-Discussion mailing list