summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorand-sang <53617841+and-sang@users.noreply.github.com>2020-02-28 18:55:14 +0100
committerGitHub <noreply@github.com>2020-02-28 12:55:14 -0500
commiteb167a3fe540780f397a14817f54a95333fbcc6c (patch)
tree37c00d8a53ac84aee27db5c4029db2205347081f
parent94d3302039856667988f82d637f9a35998d19a79 (diff)
downloadnumpy-eb167a3fe540780f397a14817f54a95333fbcc6c.tar.gz
DOC: Update to clarify actual behavior real_if_(all elements)_close (gh-15644)
Updated the description to consider all array elements Updated the examples to use multiple elements array, to show that one element not close enough prevent for the whole array to be considered as real Closes #15626
-rw-r--r--numpy/lib/type_check.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 13db9adc3..2a2982ab3 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -492,7 +492,8 @@ def _real_if_close_dispatcher(a, tol=None):
@array_function_dispatch(_real_if_close_dispatcher)
def real_if_close(a, tol=100):
"""
- If complex input returns a real array if complex parts are close to zero.
+ If input is complex with all imaginary parts close to zero, return
+ real parts.
"Close to zero" is defined as `tol` * (machine epsilon of the type for
`a`).
@@ -527,10 +528,10 @@ def real_if_close(a, tol=100):
>>> np.finfo(float).eps
2.2204460492503131e-16 # may vary
- >>> np.real_if_close([2.1 + 4e-14j], tol=1000)
- array([2.1])
- >>> np.real_if_close([2.1 + 4e-13j], tol=1000)
- array([2.1+4.e-13j])
+ >>> np.real_if_close([2.1 + 4e-14j, 5.2 + 3e-15j], tol=1000)
+ array([2.1, 5.2])
+ >>> np.real_if_close([2.1 + 4e-13j, 5.2 + 3e-15j], tol=1000)
+ array([2.1+4.e-13j, 5.2 + 3e-15j])
"""
a = asanyarray(a)