Return the mask of a masked array, or nomask. Return the mask of `a` as an ndarray if `a` is a `MaskedArray` and the mask is not `nomask`, else return `nomask`. To guarantee a full array of booleans of the same shape as a, use `getmaskarray`. Parameters ---------- a :
(a)
| 1360 | |
| 1361 | |
| 1362 | def getmask(a): |
| 1363 | """ |
| 1364 | Return the mask of a masked array, or nomask. |
| 1365 | |
| 1366 | Return the mask of `a` as an ndarray if `a` is a `MaskedArray` and the |
| 1367 | mask is not `nomask`, else return `nomask`. To guarantee a full array |
| 1368 | of booleans of the same shape as a, use `getmaskarray`. |
| 1369 | |
| 1370 | Parameters |
| 1371 | ---------- |
| 1372 | a : array_like |
| 1373 | Input `MaskedArray` for which the mask is required. |
| 1374 | |
| 1375 | See Also |
| 1376 | -------- |
| 1377 | getdata : Return the data of a masked array as an ndarray. |
| 1378 | getmaskarray : Return the mask of a masked array, or full array of False. |
| 1379 | |
| 1380 | Examples |
| 1381 | -------- |
| 1382 | >>> import numpy.ma as ma |
| 1383 | >>> a = ma.masked_equal([[1,2],[3,4]], 2) |
| 1384 | >>> a |
| 1385 | masked_array( |
| 1386 | data=[[1, --], |
| 1387 | [3, 4]], |
| 1388 | mask=[[False, True], |
| 1389 | [False, False]], |
| 1390 | fill_value=2) |
| 1391 | >>> ma.getmask(a) |
| 1392 | array([[False, True], |
| 1393 | [False, False]]) |
| 1394 | |
| 1395 | Equivalently use the `MaskedArray` `mask` attribute. |
| 1396 | |
| 1397 | >>> a.mask |
| 1398 | array([[False, True], |
| 1399 | [False, False]]) |
| 1400 | |
| 1401 | Result when mask == `nomask` |
| 1402 | |
| 1403 | >>> b = ma.masked_array([[1,2],[3,4]]) |
| 1404 | >>> b |
| 1405 | masked_array( |
| 1406 | data=[[1, 2], |
| 1407 | [3, 4]], |
| 1408 | mask=False, |
| 1409 | fill_value=999999) |
| 1410 | >>> ma.nomask |
| 1411 | False |
| 1412 | >>> ma.getmask(b) == ma.nomask |
| 1413 | True |
| 1414 | >>> b.mask == ma.nomask |
| 1415 | True |
| 1416 | |
| 1417 | """ |
| 1418 | return getattr(a, '_mask', nomask) |
| 1419 |
no outgoing calls