Assigns values from one structured array to another by field name. Normally in numpy >= 1.14, assignment of one structured array to another copies fields "by position", meaning that the first field from the src is copied to the first field of the dst, and so on, regardless of field
(dst, src, zero_unassigned=True)
| 1226 | |
| 1227 | @array_function_dispatch(_assign_fields_by_name_dispatcher) |
| 1228 | def assign_fields_by_name(dst, src, zero_unassigned=True): |
| 1229 | """ |
| 1230 | Assigns values from one structured array to another by field name. |
| 1231 | |
| 1232 | Normally in numpy >= 1.14, assignment of one structured array to another |
| 1233 | copies fields "by position", meaning that the first field from the src is |
| 1234 | copied to the first field of the dst, and so on, regardless of field name. |
| 1235 | |
| 1236 | This function instead copies "by field name", such that fields in the dst |
| 1237 | are assigned from the identically named field in the src. This applies |
| 1238 | recursively for nested structures. This is how structure assignment worked |
| 1239 | in numpy >= 1.6 to <= 1.13. |
| 1240 | |
| 1241 | Parameters |
| 1242 | ---------- |
| 1243 | dst : ndarray |
| 1244 | src : ndarray |
| 1245 | The source and destination arrays during assignment. |
| 1246 | zero_unassigned : bool, optional |
| 1247 | If True, fields in the dst for which there was no matching |
| 1248 | field in the src are filled with the value 0 (zero). This |
| 1249 | was the behavior of numpy <= 1.13. If False, those fields |
| 1250 | are not modified. |
| 1251 | """ |
| 1252 | |
| 1253 | if dst.dtype.names is None: |
| 1254 | dst[...] = src |
| 1255 | return |
| 1256 | |
| 1257 | for name in dst.dtype.names: |
| 1258 | if name not in src.dtype.names: |
| 1259 | if zero_unassigned: |
| 1260 | dst[name] = 0 |
| 1261 | else: |
| 1262 | assign_fields_by_name(dst[name], src[name], |
| 1263 | zero_unassigned) |
| 1264 | |
| 1265 | def _require_fields_dispatcher(array, required_dtype): |
| 1266 | return (array,) |
no outgoing calls