Python -zelfstudie

Python HOME Python-intro Python Aan de slag Python-syntaxis Python-opmerkingen Python-variabelen Python-gegevenstypen Python-nummers Python-casting Python-snaren Python Booleans Python-operators Python-lijsten Python-tupels Python-sets Python-woordenboeken Python Als...Anders Python While-lussen Python voor lussen Python-functies Python Lambda Python-arrays Python-klassen/objecten Python-overerving Python-iterators Python-bereik Python-modules Python-datums Python-wiskunde Python JSON Python RegEx Python PIP Python proberen...Behalve Python-gebruikersinvoer Opmaak van Python-tekenreeksen

Bestandsbehandeling

Python-bestandsafhandeling Python-bestanden lezen Python bestanden schrijven/maken Python bestanden verwijderen

Python-modules

NumPy-zelfstudie Panda walkthrough Scipy-zelfstudie

Python Matplotlib

Matplotlib Intro Matplotlib Aan de slag Matplotlib Pyplot Matplotlib plotten Matplotlib-markeringen Matplotlib-lijn Matplotlib-labels Matplotlib-raster Matplotlib-subplots Matplotlib Scatter Matplotlib-repen Matplotlib-histogrammen Matplotlib-cirkeldiagrammen

Machinaal leren

Beginnen Gemiddelde mediane modus Standaardafwijking percentiel Gegevensdistributie Normale gegevensverdeling Spreidingsplot Lineaire regressie Polynomiale regressie Meervoudige regressie Schaal Trein/Test Beslissingsboom

Python MySQL

MySQL Aan de slag MySQL Database maken MySQL-tabel maken MySQL-invoeging MySQL Select MySQL Waar MySQL Bestel op MySQL verwijderen MySQL-droptabel MySQL-update MySQL-limiet MySQL Join

Python MongoDB

MongoDB Aan de slag MongoDB Database maken MongoDB Verzameling maken MongoDB invoegen MongoDB Zoeken MongoDB-query MongoDB Sorteren MongoDB verwijderen MongoDB Drop-collectie MongoDB-update MongoDB-limiet

Python-referentie

Python-overzicht Ingebouwde functies van Python Python-stringmethoden Methoden voor Python-lijst Python-woordenboekmethoden Python Tuple-methoden Methoden voor Python-sets Python-bestandsmethoden Python-trefwoorden Python-uitzonderingen Python-woordenlijst

Modulereferentie

Willekeurige module Verzoekmodule Statistiekmodule Wiskundige module cMath-module

Python-instructies

Lijstduplicaten verwijderen Een string omkeren Voeg twee nummers toe

Python-voorbeelden

Python-voorbeelden Python-compiler Python-oefeningen Python-quiz Python-certificaat

Python cmath.isclose() Methode

❮ cmath-methoden


Voorbeeld

Vergelijk de nabijheid van twee complexe waarden:

#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))

Definitie en gebruik

De cmath.isclose()methode controleert of twee complexe waarden dicht bij elkaar liggen of niet. Deze methode retourneert een Booleaanse waarde: Trueals de waarden dichtbij zijn, anders False.

Deze methode gebruikt een relatieve tolerantie of een absolute tolerantie om te zien of de waarden dicht bij elkaar liggen.

Tip: Het gebruikt de volgende formule om de waarden te vergelijken:
abs(ab) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)


Syntaxis

cmath.isclose(a, b, rel_tol = value, abs_tol = value)

Parameterwaarden

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

Technische details

Winstwaarde: Een boolwaarde. Trueals de waarden dicht bij elkaar liggen, andersFalse
Python-versie: 3.5

Meer voorbeelden

Voorbeeld

Vergelijk de nabijheid van twee complexe waarden waarbij absolute tolerantie is gedefinieerd:

#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))

❮ cmath-methoden