|
10 | 10 | """
|
11 | 11 | __all__ = [
|
12 | 12 | 'apply_along_axis', 'apply_over_axes', 'atleast_1d', 'atleast_2d',
|
13 |
| - 'atleast_3d', 'average', 'clump_masked', 'clump_unmasked', |
14 |
| - 'column_stack', 'compress_cols', 'compress_nd', 'compress_rowcols', |
15 |
| - 'compress_rows', 'count_masked', 'corrcoef', 'cov', 'diagflat', 'dot', |
16 |
| - 'dstack', 'ediff1d', 'flatnotmasked_contiguous', 'flatnotmasked_edges', |
17 |
| - 'hsplit', 'hstack', 'isin', 'in1d', 'intersect1d', 'mask_cols', 'mask_rowcols', |
18 |
| - 'mask_rows', 'masked_all', 'masked_all_like', 'median', 'mr_', |
| 13 | + 'atleast_3d', 'average', 'clump_masked', 'clump_unmasked', 'column_stack', |
| 14 | + 'compress_cols', 'compress_nd', 'compress_rowcols', 'compress_rows', |
| 15 | + 'count_masked', 'corrcoef', 'cov', 'diagflat', 'dot', 'dstack', 'ediff1d', |
| 16 | + 'flatnotmasked_contiguous', 'flatnotmasked_edges', 'hsplit', 'hstack', |
| 17 | + 'isin', 'in1d', 'intersect1d', 'mask_cols', 'mask_rowcols', 'mask_rows', |
| 18 | + 'masked_all', 'masked_all_like', 'median', 'mr_', 'ndenumerate', |
19 | 19 | 'notmasked_contiguous', 'notmasked_edges', 'polyfit', 'row_stack',
|
20 | 20 | 'setdiff1d', 'setxor1d', 'stack', 'unique', 'union1d', 'vander', 'vstack',
|
21 | 21 | ]
|
@@ -1520,6 +1520,51 @@ def __init__(self):
|
1520 | 1520 | #---- Find unmasked data ---
|
1521 | 1521 | #####--------------------------------------------------------------------------
|
1522 | 1522 |
|
| 1523 | +def ndenumerate(a): |
| 1524 | + """ |
| 1525 | + Multidimensional index iterator. |
| 1526 | +
|
| 1527 | + Return an iterator yielding pairs of array coordinates and values of |
| 1528 | + elements that are not masked. |
| 1529 | +
|
| 1530 | + Parameters |
| 1531 | + ---------- |
| 1532 | + a : array_like |
| 1533 | + An array with (possibly) masked elements. |
| 1534 | +
|
| 1535 | + See Also |
| 1536 | + -------- |
| 1537 | + numpy.ndenumerate : Equivalent function ignoring any mask. |
| 1538 | +
|
| 1539 | + Examples |
| 1540 | + -------- |
| 1541 | + >>> a = np.ma.arange(9).reshape((3, 3)) |
| 1542 | + >>> a[1, 0] = np.ma.masked |
| 1543 | + >>> a[1, 2] = np.ma.masked |
| 1544 | + >>> a[2, 1] = np.ma.masked |
| 1545 | + >>> a |
| 1546 | + masked_array( |
| 1547 | + data=[[0, 1, 2], |
| 1548 | + [--, 4, --], |
| 1549 | + [6, --, 8]], |
| 1550 | + mask=[[False, False, False], |
| 1551 | + [ True, False, True], |
| 1552 | + [False, True, False]], |
| 1553 | + fill_value=999999) |
| 1554 | + >>> for index, x in np.ma.ndenumerate(a): |
| 1555 | + ... print(index, x) |
| 1556 | + (0, 0) 0 |
| 1557 | + (0, 1) 1 |
| 1558 | + (0, 2) 2 |
| 1559 | + (1, 1) 4 |
| 1560 | + (2, 0) 6 |
| 1561 | + (2, 2) 8 |
| 1562 | + """ |
| 1563 | + for it, masked in zip(np.ndenumerate(a), getmaskarray(a).flat): |
| 1564 | + if not masked: |
| 1565 | + yield it |
| 1566 | + |
| 1567 | + |
1523 | 1568 | def flatnotmasked_edges(a):
|
1524 | 1569 | """
|
1525 | 1570 | Find the indices of the first and last unmasked values.
|
|
0 commit comments