Overview:
-
The NumPy function isreal() checks each the element of a NumPy array-like, whether the element is a real number. If the element is a real number, the result of the test is True. The result is False otherwise. The results are returned as a Boolean array. If the input to the function is a scalar a single Boolean value is returned.
-
Real numbers are subset of complex numbers. Hence, the function isreal() will return True for a complex number whose imaginary part is zero. Whereas, the iscomplex() function will return True only if the complex number has a non-zero imaginary part.
Example:
# Example Python program that checks elements # Create an ndarray # Populate the ndarray with a mix of numbers including integers, # Integers # Rational numbers # Irrational numbers # Complex numbers numbers[0][0] = r1 numbers[1][0] = r5 print("Numbers:") |
Output:
Numbers: [[-1. +0.j 3. +0.j 0.75 +0.j 0.33333333+0.j] [ 0.14285714+0.j 1.41421356+0.j 10. +0.j 1. -2.j]] Numpy.isreal() results: [[ True True True True] [ True True True False]] |