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

Vincent Davis vincent@vincentdavis....
Sat Mar 6 15:08:02 CST 2010


Again I am new to this but I spent 2hr on this and looked at the
documentation an tutorials. To be fare there are not a lot of examples using
strings.
I would suggest that there are two many ways to specify dtype. At least that
is my impression.
I would find a nice table that list all with the different way they are
used.

for example
@ Ryan used ('xb','S5')
@ Christopher used  ('xb', '|S10')
I tried ('xb', |S10)
there is also a10 or somthing
numpy.float64() can be used

Is it possible for me to help contribute something like this. As I learn
more about python and numpy I often come across topics that are not very
clear to me, or could benefit from more/different examples. I assume this is
most applicable to the tutorials.

Thanks again

  *Vincent Davis
720-301-3003 *
vincent@vincentdavis.net
 my blog <http://vincentdavis.net> |
LinkedIn<http://www.linkedin.com/in/vincentdavis>


On Sat, Mar 6, 2010 at 11:46 AM, Robert Kern <robert.kern@gmail.com> wrote:

> On Sat, Mar 6, 2010 at 11:26, Ryan May <rmay31@gmail.com> wrote:
> > On Sat, Mar 6, 2010 at 10:44 AM, Vincent Davis <vincent@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).
>
> np.array() is a complicated function with many codepaths. It can do
> some autodetection for simple dtypes, but it would be difficult to
> write one for structured dtypes, I think.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>  -- Umberto Eco
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100306/8b5ca997/attachment.html 


More information about the SciPy-User mailing list