Build a masked array from a suitable flexible-type array. The input array has to have a data-type with ``_data`` and ``_mask`` fields. This type of array is output by `MaskedArray.toflex`. Parameters ---------- fxarray : ndarray The structured input array, containi
(fxarray)
| 8310 | |
| 8311 | |
| 8312 | def fromflex(fxarray): |
| 8313 | """ |
| 8314 | Build a masked array from a suitable flexible-type array. |
| 8315 | |
| 8316 | The input array has to have a data-type with ``_data`` and ``_mask`` |
| 8317 | fields. This type of array is output by `MaskedArray.toflex`. |
| 8318 | |
| 8319 | Parameters |
| 8320 | ---------- |
| 8321 | fxarray : ndarray |
| 8322 | The structured input array, containing ``_data`` and ``_mask`` |
| 8323 | fields. If present, other fields are discarded. |
| 8324 | |
| 8325 | Returns |
| 8326 | ------- |
| 8327 | result : MaskedArray |
| 8328 | The constructed masked array. |
| 8329 | |
| 8330 | See Also |
| 8331 | -------- |
| 8332 | MaskedArray.toflex : Build a flexible-type array from a masked array. |
| 8333 | |
| 8334 | Examples |
| 8335 | -------- |
| 8336 | >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[0] + [1, 0] * 4) |
| 8337 | >>> rec = x.toflex() |
| 8338 | >>> rec |
| 8339 | array([[(0, False), (1, True), (2, False)], |
| 8340 | [(3, True), (4, False), (5, True)], |
| 8341 | [(6, False), (7, True), (8, False)]], |
| 8342 | dtype=[('_data', '<i8'), ('_mask', '?')]) |
| 8343 | >>> x2 = np.ma.fromflex(rec) |
| 8344 | >>> x2 |
| 8345 | masked_array( |
| 8346 | data=[[0, --, 2], |
| 8347 | [--, 4, --], |
| 8348 | [6, --, 8]], |
| 8349 | mask=[[False, True, False], |
| 8350 | [ True, False, True], |
| 8351 | [False, True, False]], |
| 8352 | fill_value=999999) |
| 8353 | |
| 8354 | Extra fields can be present in the structured array but are discarded: |
| 8355 | |
| 8356 | >>> dt = [('_data', '<i4'), ('_mask', '|b1'), ('field3', '<f4')] |
| 8357 | >>> rec2 = np.zeros((2, 2), dtype=dt) |
| 8358 | >>> rec2 |
| 8359 | array([[(0, False, 0.), (0, False, 0.)], |
| 8360 | [(0, False, 0.), (0, False, 0.)]], |
| 8361 | dtype=[('_data', '<i4'), ('_mask', '?'), ('field3', '<f4')]) |
| 8362 | >>> y = np.ma.fromflex(rec2) |
| 8363 | >>> y |
| 8364 | masked_array( |
| 8365 | data=[[0, 0], |
| 8366 | [0, 0]], |
| 8367 | mask=[[False, False], |
| 8368 | [False, False]], |
| 8369 | fill_value=999999, |