summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hirwa Nshuti <hirwanshutiflx@gmail.com>2022-10-11 19:25:10 +0530
committerGitHub <noreply@github.com>2022-10-11 15:55:10 +0200
commit7036b164ed1d59df870c35a90ab2e6148ba976cc (patch)
tree37659d69152bf6e930e35ed9a4081a211fd7fc9d
parent4d19f55dd94eb16e02a605ce963d02c51411057d (diff)
downloadnumpy-7036b164ed1d59df870c35a90ab2e6148ba976cc.tar.gz
DOC: added `ma.round` and `ma.round_` examples (#22404)
This PR is partially addressing #22269 Added examples for ma.round and ma.round_
-rw-r--r--numpy/ma/core.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 0ee630a97..902a25b67 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -7503,6 +7503,28 @@ def round_(a, decimals=0, out=None):
If out is given and does not have a mask attribute, the mask of a
is lost!
+ Examples
+ --------
+ >>> import numpy.ma as ma
+ >>> x = [11.2, -3.973, 0.801, -1.41]
+ >>> mask = [0, 0, 0, 1]
+ >>> masked_x = ma.masked_array(x, mask)
+ >>> masked_x
+ masked_array(data=[11.2, -3.973, 0.801, --],
+ mask=[False, False, False, True],
+ fill_value=1e+20)
+ >>> ma.round_(masked_x)
+ masked_array(data=[11.0, -4.0, 1.0, --],
+ mask=[False, False, False, True],
+ fill_value=1e+20)
+ >>> ma.round(masked_x, decimals=1)
+ masked_array(data=[11.2, -4.0, 0.8, --],
+ mask=[False, False, False, True],
+ fill_value=1e+20)
+ >>> ma.round_(masked_x, decimals=-1)
+ masked_array(data=[10.0, -0.0, 0.0, --],
+ mask=[False, False, False, True],
+ fill_value=1e+20)
"""
if out is None:
return np.round_(a, decimals, out)