MCPcopy Create free account
hub / github.com/numpy/numpy / recursive_fill_fields

Function recursive_fill_fields

numpy/lib/recfunctions.py:36–71  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

test_simple_flexibleMethod · 0.90
test_masked_flexibleMethod · 0.90
drop_fieldsFunction · 0.85
_keep_fieldsFunction · 0.85
append_fieldsFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_simple_flexibleMethod · 0.72
test_masked_flexibleMethod · 0.72