Retrieving field formats of numpy record array as list
Question: I am trying regularize the formats of a pytable and recarray for the purposes
of appending the recarray to the pytable. To do this I need to get field
information from the recarray (i.e. names and field formats) I can easily get
a list of the recarray names using:

    
    
    namelist = Myrecarray.dtype.names
    

but have not found a corresponding property. The recarray dtypes property
returns a tuple list of name and format but it is not possible to iterate over
this list to retrieve the formats. This seems non-standard as I am able to
iterate over other lists of tuples to obtain specific tuple items. For
example, the following code shows iteration over an array and recarray, and
attempts to iterate over the list of tuples of the dtype of a recarray:

    
    
    import numpy as np
    
    my_list = [(1, 2), (3, 4), (5, 6)]
    print([x[0] for x in my_list])
    print('-----------------------')
    
    my_array =  np.array([(1.0, 2, 5), (3.0, 4, 77)], dtype=[('x', float), ('y', int), ('z', float)])
    print([x[2] for x in my_array])
    print('-----------------------')
    
    img = np.array([[(0,0,0), (1,0,0)], [(0,1,0), (0,0,1)]], {'names': ('r','g','b'), 'formats': ('f4', 'i2', 'f4')})
    nta = np.array(img.dtype)
    print(img.dtype)
    print(img.dtype.names)
    print(img.dtype[0])
    print(nta)
    print([x[0] for x in nta])
    print([x[0] for x in img.dtype])
    

The printouts from this code (shown below) suggest that I can: 1) iterate over
a list of tuples;  
2) iterate over a recarray; 3) retrieve the dtype of a record array as an
apparent list of tuples;  
4) retrieve the names from the recarray 5) retrieve the format of one field of
the recarray

but that I can not:

6) iterate over the recarray dtype to retrieve the format of each field 7)
iterate over the recarray dtype cast as an array to retrieve the format of
each field

the output is:

    
    
    [1, 3, 5]
    -----------------------
    [5.0, 77.0]
    -----------------------
    [('r', '<f4'), ('g', '<i2'), ('b', '<f4')]
    ('r', 'g', 'b')
    float32
    [('r', '<f4'), ('g', '<i2'), ('b', '<f4')]
    'import sitecustomize' failed; use -v for traceback
    Traceback (most recent call last):
      File "....\Python\test0.py", line 23, in <module>
        print([x[0] for x in nta])
    TypeError: iteration over a 0-d array
    

Does anyone know how to retrieve the field formats from a record array as a
list?


Answer: Hmmmm, newbie found an answer to his own question. I needed the "descr"
property to turn it into an iterable object

    
    
    print([x[1] for x in img.dtype.descr])
    

