ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.includehelp.com/python/how-to-remove-nan-values-from-a-given-numpy-array.aspx |
| Last Crawled | 2026-04-13 03:46:23 (14 hours ago) |
| First Indexed | 2022-12-17 03:20:41 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to remove NaN values from a given NumPy array? |
| Meta Description | In this tutorial, we will learn how to remove NaN values from a given NumPy array? |
| Meta Canonical | null |
| Boilerpipe Text | Home
»
Python
»
Python Programs
In this tutorial, we will learn how to remove NaN values from a given NumPy array?
By
Pranit Sharma
Last updated : May 23, 2023
Suppose we need to create a NumPy array of length n, and each element of this array would be e a single value (say 5).
Removing NaN values from a given NumPy array
To remove NaN values from a given NumPy array, you can use a method provided by NumPy called the
full()
method. This method is better than the
empty()
followed by the
fill()
method.
This is arguably the way of creating an array filled with certain values because it explicitly describes what is being achieved.
Let us understand with the help of an example,
Python program to remove NaN values from a given NumPy array
# Import numpy
import
numpy
as
np
# Creating a numpy array
arr
=
np
.
array([
1
,
2
, np
.
NaN,
4
, np
.
NaN,
8
])
# Display original array
print
(
"Orignal array:
\n
"
,arr,
"
\n
"
)
# Extracting non null values
res
=
arr[
~
np
.
isnan(arr)]
# Display Result
print
(
"Result:
\n
"
,res,
"
\n
"
)
Output
Python NumPy Programs »
Advertisement
Advertisement |
| Markdown | null |
| Readable Markdown | [Home](https://www.includehelp.com/default.aspx) » [Python](https://www.includehelp.com/python/default.aspx) » [Python Programs](https://www.includehelp.com/python/programs.aspx)
In this tutorial, we will learn how to remove NaN values from a given NumPy array? By [Pranit Sharma](https://www.includehelp.com/Members/Pranit-Sharma.aspx) Last updated : May 23, 2023
Suppose we need to create a NumPy array of length n, and each element of this array would be e a single value (say 5).
## Removing NaN values from a given NumPy array
To remove NaN values from a given NumPy array, you can use a method provided by NumPy called the full() method. This method is better than the empty() followed by the fill() method.
This is arguably the way of creating an array filled with certain values because it explicitly describes what is being achieved.
Let us understand with the help of an example,
## Python program to remove NaN values from a given NumPy array
```
# Import numpy
import numpy as np
# Creating a numpy array
arr = np.array([1, 2, np.NaN, 4, np.NaN, 8])
# Display original array
print("Orignal array:\n",arr,"\n")
# Extracting non null values
res = arr[~np.isnan(arr)]
# Display Result
print("Result:\n",res,"\n")
```
### Output

[Python NumPy Programs »](https://www.includehelp.com/python/numpy-programs.aspx)
Advertisement
Advertisement |
| Shard | 106 (laksa) |
| Root Hash | 1184066710662109106 |
| Unparsed URL | com,includehelp!www,/python/how-to-remove-nan-values-from-a-given-numpy-array.aspx s443 |