When working with floating-point numbers, it is important to be aware of their limitations due to the way they are represented in binary form. Due to rounding errors, floating-point numbers may not always compare equal even when they are mathematically equal. Numpy provides several special functions to handle these cases and perform comparison operations on floating-point numbers correctly. Some of these functions are:
1. isinf() function:
This function returns a Boolean array of the same shape as the input array, where each element is True if the corresponding element in the input array is infinity, and False otherwise.Let understand it better by example given below:
2. isnan() function:
This function returns a Boolean array of the same shape as the input array, where each element is True if the corresponding element in the input array is NaN (not a number), and False otherwise.Let me show you, how it works.
3. isfinite() function:
This function returns a Boolean array of the same shape as the input array, where each element is True if the corresponding element in the input array is a finite number (i.e., not NaN or infinity), and False otherwise.For better understanding, let look the example given below: