पायथन cmath.isclose () विधि
उदाहरण
दो जटिल मूल्यों की निकटता की तुलना करें:
#Import cmath Library
import cmath
#compare the closeness of two
complex values using relative tolerance
print(cmath.isclose(10+5j,
10+5j))
print(cmath.isclose(10+5j, 10.01+5j))
परिभाषा और उपयोग
cmath.isclose()
विधि जांचती है कि दो जटिल मान करीब हैं या नहीं । यह विधि एक बूलियन मान लौटाती है: True
यदि मान करीब हैं, अन्यथा False
।
यह विधि एक सापेक्ष सहिष्णुता या पूर्ण सहिष्णुता का उपयोग करती है, यह देखने के लिए कि क्या मान करीब हैं।
युक्ति: यह मानों की तुलना करने के लिए निम्न सूत्र का उपयोग करता है:
abs(ab) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
वाक्य - विन्यास
cmath.isclose(a, b, rel_tol = value, abs_tol = value)
पैरामीटर मान
Parameter | Description |
---|---|
a | Required. The first value to check for closeness |
b | Required. The second value to check for closeness |
rel_tol = value | Optional. The relative tolerance. It is the maximum allowed difference between value a and b. Default value is 1e-09 |
abs_tol = value | Optional. The minimum absolute tolerance. It is used to compare values near 0. The value must be at least 0 |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | एक bool मूल्य। True यदि मान करीब हैं, अन्यथाFalse |
---|---|
पायथन संस्करण: | 3.5 |
और ज्यादा उदाहरण
उदाहरण
दो जटिल मूल्यों की निकटता की तुलना करें जहां पूर्ण सहिष्णुता परिभाषित की गई है:
#Import cmath Library
import cmath
#compare the closeness of two
complex values using absolute tolerance
print(cmath.isclose(10+5j, 10+5j,
abs_tol=0.005))
print(cmath.isclose(10+5j, 10.01+5j, abs_tol=0.005))