- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Test element-wise for positive or negative infinity in Numpy
To test element-wise for positive or negative infinity, use the numpy.isinf() method in Python Numpy. Returns a boolean array of the same shape as x, True where x == +/-inf, otherwise False.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). Errors result if the second argument is supplied when the first argument is a scalar, or if the first and second arguments have different shapes.
Steps
At first, import the required library −
import numpy as np
To test element-wise for positive or negative infinity, use the numpy.isinf() method in Python Numpy.
Checking for numbers −
print("Infinite? ", np.isinf(1)) print("
Infinite? ", np.isinf(0))
Checking for float −
print("
Infinite? ", np.isinf(14.)) print("
Infinite? ", np.isinf(3.6))
Checking for NaN −
print("
Infinite? ", np.isinf(np.nan)) print("
Infinite? ", np.isinf(np.NAN))
Checking for infinity −
print("
Infinite? ", np.isinf(np.inf)) print("
Infinite? ", np.isinf(np.NINF))
Checking for log −
print("
Infinite? ", np.isinf(np.log(1))) print("
Infinite? ", np.isinf(np.log(2)))
Example
import numpy as np # To test element-wise for positive or negative infinity, use the numpy.isinf() method in Python Numpy # Checking for numbers print("Infinite? ", np.isinf(1)) print("
Infinite? ", np.isinf(0)) # Checking for float print("
Infinite? ", np.isinf(14.)) print("
Infinite? ", np.isinf(3.6)) # Checking for NaN print("
Infinite? ", np.isinf(np.nan)) print("
Infinite? ", np.isinf(np.NAN)) # Checking for infinity print("
Infinite? ", np.isinf(np.inf)) print("
Infinite? ", np.isinf(np.NINF)) # Checking for log print("
Infinite? ", np.isinf(np.log(1))) print("
Infinite? ", np.isinf(np.log(2)))
Output
Infinite? False Infinite? False Infinite? False Infinite? False Infinite? False Infinite? False Infinite? True Infinite? True Infinite? False Infinite? False
- Related Articles
- Test array values for positive or negative infinity in Numpy
- Display the Numerical positive and negative element-wise in Numpy
- Test element-wise for NaN in Numpy
- Test element-wise for NaT (not a time) in Numpy
- Compute the bit-wise OR of two Numpy arrays element-wise
- Return the non-negative square-root of an array element-wise in Numpy
- Compute the bit-wise OR of two boolean arrays element-wise in Numpy
- How to print positive and negative infinity values in JavaScript?
- Compute the bit-wise OR of two Two-Dimensional arrays element-wise in Numpy
- Compute the bit-wise OR of two One-Dimensional Numpy arrays element-wise
- Subtract arguments element-wise in Numpy
- Compute the bit-wise OR of a 1D and a 2D array element-wise in Numpy
- Return element-wise title cased version of string or Unicode in Numpy
- True Divide arguments element-wise in Numpy
- Test finiteness (not infinity and not Not a Number) in Numpy

Advertisements