

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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("\nInfinite? ", np.isinf(0))
Checking for float −
print("\nInfinite? ", np.isinf(14.)) print("\nInfinite? ", np.isinf(3.6))
Checking for NaN −
print("\nInfinite? ", np.isinf(np.nan)) print("\nInfinite? ", np.isinf(np.NAN))
Checking for infinity −
print("\nInfinite? ", np.isinf(np.inf)) print("\nInfinite? ", np.isinf(np.NINF))
Checking for log −
print("\nInfinite? ", np.isinf(np.log(1))) print("\nInfinite? ", 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("\nInfinite? ", np.isinf(0)) # Checking for float print("\nInfinite? ", np.isinf(14.)) print("\nInfinite? ", np.isinf(3.6)) # Checking for NaN print("\nInfinite? ", np.isinf(np.nan)) print("\nInfinite? ", np.isinf(np.NAN)) # Checking for infinity print("\nInfinite? ", np.isinf(np.inf)) print("\nInfinite? ", np.isinf(np.NINF)) # Checking for log print("\nInfinite? ", np.isinf(np.log(1))) print("\nInfinite? ", 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 Questions & Answers
- 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
- How to print positive and negative infinity values in JavaScript?
- Compute the bit-wise OR of two Numpy arrays element-wise
- Compute the bit-wise OR of two boolean arrays element-wise in Numpy
- Return the non-negative square-root of an array element-wise in Numpy
- Compute the bit-wise OR of two One-Dimensional Numpy arrays element-wise
- Compute the bit-wise OR of two Two-Dimensional arrays element-wise in Numpy
- Subtract arguments element-wise in Numpy
- True Divide arguments element-wise in Numpy
- Test finiteness (not infinity and not Not a Number) 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
Advertisements