Fills fields from output with fields from input, with support for nested structures. Parameters ---------- input : ndarray Input array. output : ndarray Output array. Notes ----- * `output` should be at least the same size as `input` Exampl
(input, output)
| 30 | |
| 31 | @array_function_dispatch(_recursive_fill_fields_dispatcher) |
| 32 | def recursive_fill_fields(input, output): |
| 33 | """ |
| 34 | Fills fields from output with fields from input, |
| 35 | with support for nested structures. |
| 36 | |
| 37 | Parameters |
| 38 | ---------- |
| 39 | input : ndarray |
| 40 | Input array. |
| 41 | output : ndarray |
| 42 | Output array. |
| 43 | |
| 44 | Notes |
| 45 | ----- |
| 46 | * `output` should be at least the same size as `input` |
| 47 | |
| 48 | Examples |
| 49 | -------- |
| 50 | >>> import numpy as np |
| 51 | >>> from numpy.lib import recfunctions as rfn |
| 52 | >>> a = np.array([(1, 10.), (2, 20.)], dtype=[('A', np.int64), ('B', np.float64)]) |
| 53 | >>> b = np.zeros((3,), dtype=a.dtype) |
| 54 | >>> rfn.recursive_fill_fields(a, b) |
| 55 | array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', '<i8'), ('B', '<f8')]) |
| 56 | |
| 57 | """ |
| 58 | newdtype = output.dtype |
| 59 | for field in newdtype.names: |
| 60 | try: |
| 61 | current = input[field] |
| 62 | except ValueError: |
| 63 | continue |
| 64 | if current.dtype.names is not None: |
| 65 | recursive_fill_fields(current, output[field]) |
| 66 | else: |
| 67 | output[field][:len(current)] = current |
| 68 | return output |
| 69 | |
| 70 | |
| 71 | def _get_fieldspec(dtype): |
no outgoing calls
searching dependent graphs…