Set storage-indexed locations to corresponding values. This function is equivalent to `MaskedArray.put`, see that method for details. See Also -------- MaskedArray.put Examples -------- Putting values in a masked array: >>> a = np.ma.array([1, 2, 3, 4], m
(a, indices, values, mode='raise')
| 7509 | |
| 7510 | |
| 7511 | def put(a, indices, values, mode='raise'): |
| 7512 | """ |
| 7513 | Set storage-indexed locations to corresponding values. |
| 7514 | |
| 7515 | This function is equivalent to `MaskedArray.put`, see that method |
| 7516 | for details. |
| 7517 | |
| 7518 | See Also |
| 7519 | -------- |
| 7520 | MaskedArray.put |
| 7521 | |
| 7522 | Examples |
| 7523 | -------- |
| 7524 | Putting values in a masked array: |
| 7525 | |
| 7526 | >>> a = np.ma.array([1, 2, 3, 4], mask=[False, True, False, False]) |
| 7527 | >>> np.ma.put(a, [1, 3], [10, 30]) |
| 7528 | >>> a |
| 7529 | masked_array(data=[ 1, 10, 3, 30], |
| 7530 | mask=False, |
| 7531 | fill_value=999999) |
| 7532 | |
| 7533 | Using put with a 2D array: |
| 7534 | |
| 7535 | >>> b = np.ma.array([[1, 2], [3, 4]], mask=[[False, True], [False, False]]) |
| 7536 | >>> np.ma.put(b, [[0, 1], [1, 0]], [[10, 20], [30, 40]]) |
| 7537 | >>> b |
| 7538 | masked_array( |
| 7539 | data=[[40, 30], |
| 7540 | [ 3, 4]], |
| 7541 | mask=False, |
| 7542 | fill_value=999999) |
| 7543 | |
| 7544 | """ |
| 7545 | # We can't use 'frommethod', the order of arguments is different |
| 7546 | try: |
| 7547 | return a.put(indices, values, mode=mode) |
| 7548 | except AttributeError: |
| 7549 | return np.asarray(a).put(indices, values, mode=mode) |
| 7550 | |
| 7551 | |
| 7552 | def putmask(a, mask, values): # , mode='raise'): |