🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 80 (from laksa061)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
4 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.2 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.statology.org/numpy-remove-nan/
Last Crawled2026-04-06 07:04:33 (4 days ago)
First Indexed2022-05-27 19:22:16 (3 years ago)
HTTP Status Code200
Meta TitleHow to Remove NaN Values from NumPy Array (3 Methods)
Meta DescriptionThis tutorial explains how to remove nan values from a NumPy array, including several examples.
Meta Canonicalnull
Boilerpipe Text
You can use the following methods to remove NaN values from a NumPy array: Method 1: Use isnan() new_data = data[~np. isnan (data)] Method 2: Use isfinite() new_data = data[np. isfinite (data)] Method 3: Use logical_not() new_data = data[np. logical_not (np. isnan (data))] Each of these methods produce the same result, but the first method is the shortest to type out so it tends to be used most often. The following examples show how to use each method in practice. Example 1: Remove NaN Values Using isnan() The following code shows how to remove NaN values from a NumPy array by using the isnan() function: import numpy as np #create array of data data = np. array ([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[~np. isnan (data)] #view new array print (new_data) [ 4. 6. 10. 11. 14. 19. 22.] Notice that the two NaN values have been successfully removed from the NumPy array. This method simply keeps all of the elements in the array that are not (~) NaN values. Example 2: Remove NaN Values Using isfinite() The following code shows how to remove NaN values from a NumPy array by using the isfinite() function: import numpy as np #create array of data data = np. array ([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[np. isfinite (data)] #view new array print (new_data) [ 4. 6. 10. 11. 14. 19. 22.] Notice that the two NaN values have been successfully removed from the NumPy array. This method simply keeps all of the elements in the array that are finite values. Since NaN values are not finite, they’re removed from the array. Example 3: Remove NaN Values Using logical_not() The following code shows how to remove NaN values from a NumPy array by using the logical_not() function: import numpy as np #create array of data data = np. array ([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[np. logical_not (np. isnan (data))] #view new array print (new_data) [ 4. 6. 10. 11. 14. 19. 22.] Notice that the two NaN values have been successfully removed from the NumPy array. While this method is equivalent to the previous two, it requires more typing so it’s not used as often. Additional Resources The following tutorials explain how to perform other common operations in Python: Pandas: How to Replace Empty Strings with NaN Pandas: How to Replace NaN Values with String Hey there. My name is Zach Bobbitt. I have a Masters of Science degree in Applied Statistics and I’ve worked on machine learning algorithms for professional businesses in both healthcare and retail. I’m passionate about statistics, machine learning, and data visualization and I created Statology to be a resource for both students and teachers alike.  My goal with this site is to help you learn statistics through using simple terms, plenty of real-world examples, and helpful illustrations.
Markdown
[![Statology](https://www.statology.org/wp-content/uploads/2024/07/StatologyLogo_OnWhite.png)](https://www.statology.org/) - [About](https://www.statology.org/about/) - [Course](https://www.statology.org/course-register/) - [Basic Stats](https://www.statology.org/tutorials/) - [Machine Learning](https://www.statology.org/machine-learning-tutorials/) - [Software Tutorials]() - [Excel](https://www.statology.org/excel-guides/) - [Google Sheets](https://www.statology.org/google-sheets-guides/) - [MongoDB](https://www.statology.org/mongodb-guides/) - [MySQL](https://www.statology.org/mysql-guides/) - [Power BI](https://www.statology.org/power-bi-guides/) - [PySpark](https://www.statology.org/pyspark-guides/) - [Python](https://www.statology.org/python-guides/) - [R](https://www.statology.org/r-guides/) - [SAS](https://www.statology.org/sas-guides/) - [SPSS](https://www.statology.org/spss-guides/) - [Stata](https://www.statology.org/stata-guides/) - [TI-84](https://www.statology.org/ti-84-guides/) - [VBA](https://www.statology.org/vba-guides/) - [Tools]() - [Calculators](https://www.statology.org/calculators/) - [Critical Value Tables](https://www.statology.org/tables/) - [Glossary](https://www.statology.org/glossary/) # How to Remove NaN Values from NumPy Array (3 Methods) by [Zach Bobbitt](https://www.statology.org/author/admin/) Published on [Published on May 27, 2022](https://www.statology.org/numpy-remove-nan/) *** You can use the following methods to remove NaN values from a NumPy array: **Method 1: Use isnan()** ``` new_data = data[~np.isnan(data)] ``` **Method 2: Use isfinite()** ``` new_data = data[np.isfinite(data)] ``` **Method 3: Use logical\_not()** ``` new_data = data[np.logical_not(np.isnan(data))] ``` Each of these methods produce the same result, but the first method is the shortest to type out so it tends to be used most often. The following examples show how to use each method in practice. ### **Example 1: Remove NaN Values Using isnan()** The following code shows how to remove NaN values from a NumPy array by using the **isnan()** function: ``` import numpy as np #create array of data data = np.array([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[~np.isnan(data)] #view new array print(new_data) [ 4. 6. 10. 11. 14. 19. 22.] ``` Notice that the two NaN values have been successfully removed from the NumPy array. This method simply keeps all of the elements in the array that are not (~) NaN values. ### **Example 2: Remove NaN Values Using isfinite()** The following code shows how to remove NaN values from a NumPy array by using the **isfinite()** function: ``` import numpy as np #create array of data data = np.array([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[np.isfinite(data)] #view new array print(new_data) [ 4. 6. 10. 11. 14. 19. 22.] ``` Notice that the two NaN values have been successfully removed from the NumPy array. This method simply keeps all of the elements in the array that are finite values. Since NaN values are not finite, they’re removed from the array. ### **Example 3: Remove NaN Values Using logical\_not()** The following code shows how to remove NaN values from a NumPy array by using the **logical\_not()** function: ``` import numpy as np #create array of data data = np.array([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[np.logical_not(np.isnan(data))] #view new array print(new_data) [ 4. 6. 10. 11. 14. 19. 22.] ``` Notice that the two NaN values have been successfully removed from the NumPy array. While this method is equivalent to the previous two, it requires more typing so it’s not used as often. ### **Additional Resources** The following tutorials explain how to perform other common operations in Python: [Pandas: How to Replace Empty Strings with NaN](https://www.statology.org/pandas-replace-empty-string-with-nan/) [Pandas: How to Replace NaN Values with String](https://www.statology.org/pandas-replace-nan-with-string/) Posted in [Programming](https://www.statology.org/category/programming/) ![](https://www.statology.org/wp-content/uploads/2023/08/statology_gravatar-scaled.jpg) [Zach Bobbitt](https://www.statology.org/author/admin/) Hey there. My name is Zach Bobbitt. I have a Masters of Science degree in Applied Statistics and I’ve worked on machine learning algorithms for professional businesses in both healthcare and retail. I’m passionate about statistics, machine learning, and data visualization and I created Statology to be a resource for both students and teachers alike. My goal with this site is to help you learn statistics through using simple terms, plenty of real-world examples, and helpful illustrations. ## Post navigation [Prev How to Perform Bootstrapping in Python (With Example)](https://www.statology.org/bootstrapping-in-python/) [Next How to Use groupby() and transform() Functions in Pandas](https://www.statology.org/pandas-groupby-transform/) ## One Reply to “How to Remove NaN Values from NumPy Array (3 Methods)” 1. ![](https://secure.gravatar.com/avatar/bff539b7aa169fd0268c696c16a539d258ba660775b20cb346c2a0b73ea6c63f?s=68&r=g) **Sudheer** says: [September 7, 2022 at 4:42 am](https://www.statology.org/numpy-remove-nan/#comment-101872) Is there any way of removing NaN values without changing array size? [Reply](https://www.statology.org/numpy-remove-nan/#comment-101872) ### Leave a Reply [Cancel reply](https://www.statology.org/numpy-remove-nan/#respond) ## Search ## ABOUT STATOLOGY [![](https://www.statology.org/wp-content/uploads/2023/08/statology_circle-150x150.png)](https://www.statology.org/about/)Statology makes learning statistics easy by explaining topics in simple and straightforward ways. Our team of writers have over 40 years of experience in the fields of Machine Learning, AI and Statistics. **[Learn more about our team here.](https://www.statology.org/about/)** ## Featured Posts - [![](https://www.statology.org/wp-content/uploads/2026/04/sta-chugani-concise-guide-law-large-numbers-feature-150x150.png)](https://www.statology.org/the-concise-guide-to-the-law-of-large-numbers/) [The Concise Guide to the Law of Large Numbers](https://www.statology.org/the-concise-guide-to-the-law-of-large-numbers/) April 3, 2026 - [![](https://www.statology.org/wp-content/uploads/2026/03/sta-chugani-building-lightweight-data-science-environment-microsoft-stack-feature-150x150.png)](https://www.statology.org/building-a-lightweight-data-science-environment-with-the-microsoft-stack/) [Building a Lightweight Data Science Environment with the Microsoft Stack](https://www.statology.org/building-a-lightweight-data-science-environment-with-the-microsoft-stack/) April 2, 2026 - [![](https://www.statology.org/wp-content/uploads/2026/03/sta-chugani-choosing-right-statistical-software-analysis-decision-tree-approach-feature-150x150.png)](https://www.statology.org/choosing-the-right-statistical-software-for-your-analysis-a-decision-tree-approach/) [Choosing the Right Statistical Software for Your Analysis: A Decision Tree Approach](https://www.statology.org/choosing-the-right-statistical-software-for-your-analysis-a-decision-tree-approach/) April 1, 2026 - [![](https://www.statology.org/wp-content/uploads/2026/01/sta-chugani-common-regression-assumption-violations-actually-matter-feature-150x150.png)](https://www.statology.org/common-regression-assumption-violations-and-when-they-actually-matter/) [Common Regression Assumption Violations (And When They Actually Matter)](https://www.statology.org/common-regression-assumption-violations-and-when-they-actually-matter/) March 31, 2026 - [![](https://www.statology.org/wp-content/uploads/2026/02/sta-chugani-resampling-techniques-statistical-inference-feature-150x150.png)](https://www.statology.org/5-resampling-techniques-to-power-up-your-statistical-inference/) [5 Resampling Techniques to Power-Up Your Statistical Inference](https://www.statology.org/5-resampling-techniques-to-power-up-your-statistical-inference/) March 30, 2026 - [![](https://www.statology.org/wp-content/uploads/2026/03/sta-chugani-see-causality-everywhere-stats-say-no-feature-150x150.png)](https://www.statology.org/why-we-see-causality-everywhere-even-when-the-stats-say-no/) [Why We See Causality Everywhere, Even When the Stats Say No](https://www.statology.org/why-we-see-causality-everywhere-even-when-the-stats-say-no/) March 27, 2026 ## Statology Study **[Statology Study](https://www.statology.org/study-register/)** is the ultimate online statistics study guide that helps you study and practice all of the core concepts taught in any elementary statistics course and makes your life so much easier as a student. [![statology study](https://www.statology.org/wp-content/uploads/2021/01/statology_study_cover1.png)](https://www.statology.org/study-register/) ## Introduction to Statistics Course **Introduction to Statistics** is our premier online video course that teaches you all of the topics covered in introductory statistics. **[Get started](https://www.statology.org/course-register/)** with our course today. [![introduction to statistics](https://www.statology.org/wp-content/uploads/2022/06/Intro-to-Statistics-Cover-Photo-2.jpg)](https://www.statology.org/course-register/) ## You Might Also Like - [How to Replace NaN Values with Zero in NumPy](https://www.statology.org/numpy-replace-nan-with-zero/) - [NumPy: How to Count Number of Elements Equal to NaN](https://www.statology.org/numpy-count-nan/) - [How to Remove Duplicate Elements from NumPy Array](https://www.statology.org/numpy-remove-duplicates/) - [How to Add Elements to NumPy Array (3 Examples)](https://www.statology.org/numpy-array-add-element/) - [How to Convert NumPy Matrix to Array (With Examples)](https://www.statology.org/numpy-matrix-to-array/) - [How to Remove Specific Elements from NumPy Array](https://www.statology.org/numpy-remove-element-from-array/) © 2025 [Statology](https://www.statology.org/) \| [Privacy Policy](https://www.guidingtechmedia.com/privacy/) \| [Terms of Use](https://www.guidingtechmedia.com/terms-of-use/) Wisteria Theme by [WPFriendship](https://wpfriendship.com/ "WPFriendship") ⋅ Powered by [WordPress](https://wordpress.org/ "WordPress")
Readable Markdown
*** You can use the following methods to remove NaN values from a NumPy array: **Method 1: Use isnan()** ``` new_data = data[~np.isnan(data)] ``` **Method 2: Use isfinite()** ``` new_data = data[np.isfinite(data)] ``` **Method 3: Use logical\_not()** ``` new_data = data[np.logical_not(np.isnan(data))] ``` Each of these methods produce the same result, but the first method is the shortest to type out so it tends to be used most often. The following examples show how to use each method in practice. ### **Example 1: Remove NaN Values Using isnan()** The following code shows how to remove NaN values from a NumPy array by using the **isnan()** function: ``` import numpy as np #create array of data data = np.array([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[~np.isnan(data)] #view new array print(new_data) [ 4. 6. 10. 11. 14. 19. 22.] ``` Notice that the two NaN values have been successfully removed from the NumPy array. This method simply keeps all of the elements in the array that are not (~) NaN values. ### **Example 2: Remove NaN Values Using isfinite()** The following code shows how to remove NaN values from a NumPy array by using the **isfinite()** function: ``` import numpy as np #create array of data data = np.array([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[np.isfinite(data)] #view new array print(new_data) [ 4. 6. 10. 11. 14. 19. 22.] ``` Notice that the two NaN values have been successfully removed from the NumPy array. This method simply keeps all of the elements in the array that are finite values. Since NaN values are not finite, they’re removed from the array. ### **Example 3: Remove NaN Values Using logical\_not()** The following code shows how to remove NaN values from a NumPy array by using the **logical\_not()** function: ``` import numpy as np #create array of data data = np.array([4, np.nan, 6, np.nan, 10, 11, 14, 19, 22]) #define new array of data with nan values removed new_data = data[np.logical_not(np.isnan(data))] #view new array print(new_data) [ 4. 6. 10. 11. 14. 19. 22.] ``` Notice that the two NaN values have been successfully removed from the NumPy array. While this method is equivalent to the previous two, it requires more typing so it’s not used as often. ### **Additional Resources** The following tutorials explain how to perform other common operations in Python: [Pandas: How to Replace Empty Strings with NaN](https://www.statology.org/pandas-replace-empty-string-with-nan/) [Pandas: How to Replace NaN Values with String](https://www.statology.org/pandas-replace-nan-with-string/) ![](https://www.statology.org/wp-content/uploads/2023/08/statology_gravatar-scaled.jpg) Hey there. My name is Zach Bobbitt. I have a Masters of Science degree in Applied Statistics and I’ve worked on machine learning algorithms for professional businesses in both healthcare and retail. I’m passionate about statistics, machine learning, and data visualization and I created Statology to be a resource for both students and teachers alike. My goal with this site is to help you learn statistics through using simple terms, plenty of real-world examples, and helpful illustrations.
Shard80 (laksa)
Root Hash6121278954233998080
Unparsed URLorg,statology!www,/numpy-remove-nan/ s443