Hi Kirill, T 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 https://docs.scipy.org/doc/numpy/user/basics.rec.html
Jon On Fri, Mar 24, 2017 at 5:09 AM, <numpy-discussion-requ...@python.org> wrote: > From: Kirill Balunov <kirillbalu...@gmail.com> > To: numpy-discuss...@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 lists... > > 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 jsla...@cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion