Flatten a structured data-type description. Examples -------- >>> from numpy.lib import recfunctions as rfn >>> ndtype = np.dtype([('a', ' >> rfn.flatten_descr(ndtype) (('a', dtype('int32')), ('ba', dtype('float64')), ('bb'
(ndtype)
| 167 | |
| 168 | |
| 169 | def flatten_descr(ndtype): |
| 170 | """ |
| 171 | Flatten a structured data-type description. |
| 172 | |
| 173 | Examples |
| 174 | -------- |
| 175 | >>> from numpy.lib import recfunctions as rfn |
| 176 | >>> ndtype = np.dtype([('a', '<i4'), ('b', [('ba', '<f8'), ('bb', '<i4')])]) |
| 177 | >>> rfn.flatten_descr(ndtype) |
| 178 | (('a', dtype('int32')), ('ba', dtype('float64')), ('bb', dtype('int32'))) |
| 179 | |
| 180 | """ |
| 181 | names = ndtype.names |
| 182 | if names is None: |
| 183 | return (('', ndtype),) |
| 184 | else: |
| 185 | descr = [] |
| 186 | for field in names: |
| 187 | (typ, _) = ndtype.fields[field] |
| 188 | if typ.names is not None: |
| 189 | descr.extend(flatten_descr(typ)) |
| 190 | else: |
| 191 | descr.append((field, typ)) |
| 192 | return tuple(descr) |
| 193 | |
| 194 | |
| 195 | def _zip_dtype(seqarrays, flatten=False): |