NumPy: Test element-wise for NaN of a given array
NumPy: Basic Exercise-7 with Solution
Write a NumPy program to test element-wise for NaN of a given array.
Sample Solution :
Python Code :
import numpy as np a = np.array([1, 0, np.nan, np.inf]) print("Original array") print(a) print("Test element-wise for NaN:") print(np.isnan(a))
Original array [ 1. 0. nan inf] Test element-wise for NaN: [False False True False]
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a NumPy program to test element-wise for positive or negative infinity.
Next: Write a NumPy program to test element-wise for complex number, real number of a given array. Also test if a given number is a scalar type or not.
What is the difficulty level of this exercise?
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework