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

Robert Kern robert.kern@gmail....
Sat Mar 6 12:46:42 CST 2010

```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
```