numpy.real_if_close() function Python (original) (raw)
Last Updated : 11 Jun, 2020
In this **numpy.real_if_close()
**function, if complex input returns a real array then complex parts are close to zero.
Syntax : numpy.real_if_close(arr, tol = 100)
Parameters :
arr : [array_like] Input array.
tol : [float] “Close to zero” is defined as tol. Tolerance in machine epsilons for the complex part of the elements in the array.Return : [ndarray] If arr is real, the type of arr is used for the output. If arr has complex elements, the returned type is float.
Code #1 :
import
numpy as geek
arr
=
[
3.6
+
4e
-
14j
]
tol
=
1000
gfg
=
geek.real_if_close(arr, tol)
print
(gfg)
Output :
[3.6]
Code #2 :
import
numpy as geek
arr
=
[
3.6
+
2e
-
11j
]
tol
=
1000
gfg
=
geek.real_if_close(arr, tol)
print
(gfg)
Output :
[3.6+2.e-11j]
Similar Reads
- numpy.real() function - Python numpy.real() function return the real part of the complex argument. Syntax : numpy.real(arr) Parameters : arr : [array_like] Input array. Return : [ndarray or scalar] The real component of the complex argument. If val is real, the type of val is used for the output. If val has complex elements, the 1 min read
- numpy.ma.allclose() function - Python numpy.ma.allclose() function returns True if two arrays are element-wise equal within a tolerance. This function is equivalent to allclose except that masked values are treated as equal (default) or unequal, depending on the masked_equal argument. Syntax : numpy.ma.allclose(a, b, masked_equal = True 2 min read
- __closure__ magic function in Python Almost everything in Python is an object, similarly function is an object too and all the function objects have a __closure__ attribute. __closure__ is a dunder/magic function i.e. methods having two underscores as prefix and suffix in the method name A closure is a function object that remembers va 1 min read
- numpy.allclose() in Python numpy.allclose() function is used to find if two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(arr2)) and the absolute difference atol are added together to compare against the absolute differenc 3 min read
- numpy.issubclass_() function – Python numpy.issubclass_() function is used to determine whether a class is a subclass of a second class. Syntax : numpy.issubclass_(arg1, arg2) Parameters : arg1 : [class] Input class. True is returned if arg1 is a subclass of arg2. arg2 : [class or tuple of classes] Input class. If a tuple of classes, Tr 1 min read
- Python | numpy.issubdtype() function numpy.issubdtype() function is used to determine whether the first argument is a typecode lower/equal in type hierarchy from second argument.If the first argument is lower or equal it returns true, otherwise it returns false. Syntax : numpy.issubdtype(arg1, arg2) Parameters : arg1, arg2 : [dtype_lik 1 min read
- round() function in Python Python round() function is a built-in function available with Python. It will return you a float number that will be rounded to the decimal places which are given as input. If the decimal places to be rounded are not specified, it is considered as 0, and it will round to the nearest integer. In this 6 min read
- Python | numpy.issubsctype() function numpy.issubsctype() function is used to determine whether the first argumentis a subclass of the second argument.If the first argument is a subclass of the second argument it returns true, otherwise it returns false. Syntax : numpy.issubsctype(arg1, arg2) Parameters : arg1, arg2 : dtype or dtype spe 1 min read
- Python - cmath.isnan() function cMath module contains a number of functions which is used for mathematical operations for complex numbers. The cmath.isnan() function is used to check whether the value is nan (Not a Number), or not. The value passed in this function can be int, float, and complex numbers. Syntax: cmath.isnan(x) Par 1 min read
- wxPython | Exit() function in wxPython In this article we are going to learn about wx.Exit() which is a inbuilt parent function present in wxPython.Exit() function exits application after calling wx.App.OnExit . Should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to termin 1 min read