W3Schools
w3schools.com › python › ref_math_isfinite.asp
Python math.isfinite() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... # Import math Library import math # Check whether the values are finite or not print(math.isfinite(2000)) print(math.isfinite(-45.34)) print(math.isfinite(+45.34)) print(math.isfinite(math.inf)) print(math.isfinite(float("nan"))) print(math.isfinite(float("inf"))) print(math.isfinite(float("-inf"))) print(math.isfinite(-math.inf)) print(math.isfinite(0.0)) Try it Yourself »
Medium
medium.com › @whyamit404 › understanding-numpy-isfinite-with-examples-7305ff609ce9
Understanding numpy.isfinite() with Examples | by whyamit404 | Medium
March 6, 2025 - When working with numbers in Python, you’ll often encounter NaN (Not a Number) and Inf (Infinity) values. These sneaky troublemakers can mess up calculations, break models, and even cause unexpected behavior in your code. This is where numpy.isfinite() comes in—it helps you identify which numbers are valid (finite) and which ones aren't in a dataset.
NumPy
numpy.org › doc › stable › reference › generated › numpy.isfinite.html
numpy.isfinite — NumPy v2.5 Manual
>>> import numpy as np >>> np.isfinite(1) True >>> np.isfinite(0) True >>> np.isfinite(np.nan) False >>> np.isfinite(np.inf) False >>> np.isfinite(-np.inf) False >>> np.isfinite([np.log(-1.),1.,np.log(0)]) array([False, True, False])
ProgramCreek
programcreek.com › python › example › 9810 › numpy.isfinite
Python Examples of numpy.isfinite
def _check_rep(self): #name assert isinstance(self._name, str) assert len(self._name) >= 1 #bounds assert np.isfinite(self.ub) assert np.isfinite(self.lb) assert self.ub >= self.lb # value assert self._vtype in self._VALID_TYPES assert np.isnan(self.c0) or (self.c0 >= 0.0 and np.isfinite(self.c0)) return True ... def test_generic(self): with np.errstate(divide='ignore', invalid='ignore'): vals = nan_to_num(np.array((-1., 0, 1))/0.) assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0])) assert_(vals[1] == 0) assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2])) assert_equal(type(vals), np.ndarray) # perform the same test but in-place with np.errstate(divide='ignore', invalid='ignore'): vals = np.array((-1., 0, 1))/0.
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.isfinite.html
numpy.isfinite — NumPy v2.2 Manual
>>> import numpy as np >>> np.isfinite(1) True >>> np.isfinite(0) True >>> np.isfinite(np.nan) False >>> np.isfinite(np.inf) False >>> np.isfinite(-np.inf) False >>> np.isfinite([np.log(-1.),1.,np.log(0)]) array([False, True, False])
NumPy
numpy.org › devdocs › reference › generated › numpy.isfinite.html
numpy.isfinite — NumPy v2.6.dev0 Manual
>>> import numpy as np >>> np.isfinite(1) True >>> np.isfinite(0) True >>> np.isfinite(np.nan) False >>> np.isfinite(np.inf) False >>> np.isfinite(-np.inf) False >>> np.isfinite([np.log(-1.),1.,np.log(0)]) array([False, True, False])
Codecademy
codecademy.com › docs › python › math module › math.isfinite()
Python | Math Module | math.isfinite() | Codecademy
August 28, 2024 - The math.isfinite() function returns True when a number is finite and False otherwise. A finite number is neither infinite nor NaN. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Educative
educative.io › answers › what-is-numpyisfinite-in-python
What is numpy.isfinite() in Python?
The numpy.isfinite() method takes the following compulsory parameter: ... It returns False if x is positive infinity, negative infinity or NaN. It returns True in all other cases. If x is scalar, the return type is also scalar. The example below shows the use of numpy.isfinite() on the elements a and b:
IncludeHelp
includehelp.com › python › math-isfinite-method-with-example.aspx
math.isfinite() method with example in Python
Example: Input: a = 10 b = float('inf') # function call print(math.isfinite(a)) print(math.isfinite(b)) Output: True False · # python code to demonstrate example of # math.isfinite() method # importing math module import math # math.isfinite() method test on finite value print(math.isfinite(10)) ...
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.isfinite.html
numpy.isfinite — NumPy v2.1 Manual
>>> import numpy as np >>> np.isfinite(1) True >>> np.isfinite(0) True >>> np.isfinite(np.nan) False >>> np.isfinite(np.inf) False >>> np.isfinite(-np.inf) False >>> np.isfinite([np.log(-1.),1.,np.log(0)]) array([False, True, False])
W3Schools
w3schools.com › python › ref_cmath_isfinite.asp
Python cmath.isfinite() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... #import cmath for complex number operations import cmath #find whether a complex number is finite or not print (cmath.isfinite(2 + 3j)) print (cmath.isfinite(complex(5.0,float('inf')))) print (cmath.isfinite(float('inf')+ 5j)) Try it Yourself »
Python Examples
pythonexamples.org › python-math-isfinite
Python math.isfinite() – Check if Number is not Infinity or NaN
import math x = math.nan result = math.isfinite(x) print('isfinite(x) :', result) ... In this Python Math tutorial, we learned the syntax of, and examples for math.isfinite() function.
Top answer 1 of 2
6
You can use numpy.isnan to check which of the items are NaN and then find the indices of the rows which with all True's using numpy.all and numpy.where.
>>> np.isnan(raw_test)
array([[False, True],
[False, False],
[ True, True]], dtype=bool)
>>> np.all(np.isnan(raw_test), axis=1)
array([False, False, True], dtype=bool)
>>> np.where(np.all(np.isnan(raw_test), axis=1))[0]
array([2])
2 of 2
4
Another option is to use a masked_array:
import numpy as np
raw_test = np.array([[0, np.NaN], [0, 0], [np.NaN, np.NaN]])
test = np.ma.masked_invalid(raw_test)
print(test)
# [[0.0 --]
# [0.0 0.0]
# [-- --]]
def multiply(x):
return x[0] * x[1]
print(np.apply_along_axis(multiply, 1, test))
yields
[ nan 0. nan]
Learnandlearn
learnandlearn.com › python-programming › python-reference › python-isfinite-function
Loading...
This Python Programming Tutorial is designed for absolute beginners. A little or no knowledge or experience is required to learn Python Programming. This tutorial adopts beginner approach to a professional level. You have complete access to well-explained and comprehensive lectures.
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.isfinite.html
numpy.isfinite — NumPy v2.0 Manual
>>> np.isfinite(1) True >>> np.isfinite(0) True >>> np.isfinite(np.nan) False >>> np.isfinite(np.inf) False >>> np.isfinite(-np.inf) False >>> np.isfinite([np.log(-1.),1.,np.log(0)]) array([False, True, False])
Sling Academy
slingacademy.com › article › using-numpy-isfinite-function-4-examples
Using numpy.isfinite() function (4 examples) - Sling Academy
An ‘inf’ (infinity) or ‘nan’ (not a number) in the input array will yield False for that position in the output array, while all other values will return True. This function is crucial in data cleaning processes, especially when dealing with real-world data that might be imperfect or incomplete. import numpy as np # Create an array arr = np.array([1, 2, np.nan, np.inf, -np.inf, 0]) # Use isfinite result = np.isfinite(arr) # Print result print(result) ... This basic example demonstrates the immediate functionality of numpy.isfinite(), allowing us to quickly identify which elements in our array are finite.