[SciPy-User] structured array question? (slow learner :)

Ryan May rmay31 at gmail.com
Sat Mar 6 12:26:20 EST 2010


On Sat, Mar 6, 2010 at 10:44 AM, Vincent Davis <vincent at vincentdavis.net>wrote:

> Ok not sure what I am doing wrong here, In fact I am sure this was working
> and now I updated python and it doesn't now. I am skeptical that that is
> true. My question is what is happening to the strings?
>
> >>> import numpy as np
> >>> a = [(1,1),(1,2),(1,3),(2,4),(2,5),(2,6)]
> >>> b = [(1,1,'apple', 'pie'),(2,5,'boys','play')]
> >>> aa = np.array(a, [('x',int),('y',int)])
> >>> bb = np.array(b, [('x',int),('y',int), ('xb',str), ('yb',str)])
> >>> bb
> array([(1, 1, '', ''), (2, 5, '', '')],
>       dtype=[('x', '<i8'), ('y', '<i8'), ('xb', '|S0'), ('yb', '|S0')])
>

You need to give it a size for the strings (I've never really understood why
you need to with structured arrays, but not regular ones). Try this:

bb = np.array(b, [('x',int),('y',int), ('xb','S5'), ('yb','S5')])

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100306/52de355f/attachment.html>


More information about the SciPy-User mailing list