[Numpy-discussion] Structured array creation with list of lists and others

Slavin, Jonathan jslavin at cfa.harvard.edu
Fri Mar 24 09:59:23 EDT 2017

Hi Kirill,

he idea is that each tuple assigns a name to the field and a data type.
There are a variety of ways to create structured arrays but they all
involve giving both a name and data type to each field (I think).  See


On Fri, Mar 24, 2017 at 5:09 AM,  <numpy-discussion-request at python.org>
> From: Kirill Balunov <kirillbalunov at gmail.com>
> To: numpy-discussion at scipy.org
> Cc:
> Bcc:
> Date: Thu, 23 Mar 2017 21:16:28 +0300
> Subject: [Numpy-discussion] Structured array creation with list of lists
and others
> It was the first time I tried to create a structured array in numpy.
Usually I use pandas for heterogeneous arrays, but it is one more
dependency to my project.
> It took me some time (really, much more than some), to understand the
problem with structured array creation. As example:
> I had list of list of this kind:
> b=[[ 1, 10.3, 12.1, 2.12 ],...]
> And tried:
> np.array(b, dtype='i4,f4,f4,f4')
> Which raises some weird exception:
> TypeError: a bytes-like object is required, not 'int'
> Two hours later I found that I need list of tuples. I didn't find any
help in documentation and could not realize that the problem with the inner
> Why there is such restriction - 'list of tuples' to create structured
array? What is the idea behind that, why not list of lists, or tuple of
lists or ...?
> Also the exception does not help at all...
> p.s.: It looks like that dtype also accepts only list of tuples. But I
can not catch the idea for this restrictions.

Jonathan D. Slavin                 Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu       60 Garden Street, MS 83
phone: (617) 496-7981       Cambridge, MA 02138-1516
cell: (781) 363-0035             USA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170324/c7a97890/attachment.html>

More information about the NumPy-Discussion mailing list