Return True if m is a valid, standard mask. This function does not check the contents of the input, only that the type is MaskType. In particular, this function returns False if the mask has a flexible dtype. Parameters ---------- m : array_like Array to test.
(m)
| 1475 | |
| 1476 | |
| 1477 | def is_mask(m): |
| 1478 | """ |
| 1479 | Return True if m is a valid, standard mask. |
| 1480 | |
| 1481 | This function does not check the contents of the input, only that the |
| 1482 | type is MaskType. In particular, this function returns False if the |
| 1483 | mask has a flexible dtype. |
| 1484 | |
| 1485 | Parameters |
| 1486 | ---------- |
| 1487 | m : array_like |
| 1488 | Array to test. |
| 1489 | |
| 1490 | Returns |
| 1491 | ------- |
| 1492 | result : bool |
| 1493 | True if `m.dtype.type` is MaskType, False otherwise. |
| 1494 | |
| 1495 | See Also |
| 1496 | -------- |
| 1497 | ma.isMaskedArray : Test whether input is an instance of MaskedArray. |
| 1498 | |
| 1499 | Examples |
| 1500 | -------- |
| 1501 | >>> import numpy.ma as ma |
| 1502 | >>> m = ma.masked_equal([0, 1, 0, 2, 3], 0) |
| 1503 | >>> m |
| 1504 | masked_array(data=[--, 1, --, 2, 3], |
| 1505 | mask=[ True, False, True, False, False], |
| 1506 | fill_value=0) |
| 1507 | >>> ma.is_mask(m) |
| 1508 | False |
| 1509 | >>> ma.is_mask(m.mask) |
| 1510 | True |
| 1511 | |
| 1512 | Input must be an ndarray (or have similar attributes) |
| 1513 | for it to be considered a valid mask. |
| 1514 | |
| 1515 | >>> m = [False, True, False] |
| 1516 | >>> ma.is_mask(m) |
| 1517 | False |
| 1518 | >>> m = np.array([False, True, False]) |
| 1519 | >>> m |
| 1520 | array([False, True, False]) |
| 1521 | >>> ma.is_mask(m) |
| 1522 | True |
| 1523 | |
| 1524 | Arrays with complex dtypes don't return True. |
| 1525 | |
| 1526 | >>> dtype = np.dtype({'names':['monty', 'pithon'], |
| 1527 | ... 'formats':[bool, bool]}) |
| 1528 | >>> dtype |
| 1529 | dtype([('monty', '|b1'), ('pithon', '|b1')]) |
| 1530 | >>> m = np.array([(True, False), (False, True), (True, False)], |
| 1531 | ... dtype=dtype) |
| 1532 | >>> m |
| 1533 | array([( True, False), (False, True), ( True, False)], |
| 1534 | dtype=[('monty', '?'), ('pithon', '?')]) |