ℹ️ 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 | 5.4 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://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array |
| Last Crawled | 2025-10-29 23:22:22 (5 months ago) |
| First Indexed | 2022-07-30 22:13:01 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | python - How do I remove NaN values from a NumPy array? - Stack Overflow |
| Meta Description | null |
| Meta Canonical | null |
| Boilerpipe Text | To remove NaN values from a NumPy array x : x = x[~numpy.isnan(x)]
Explanation The inner function numpy.isnan returns a boolean/logical array which has the value True everywhere that x is not-a-number. Since we want the opposite, we use the logical-not operator ~ to get an array with True s everywhere that x is a valid number. Lastly, we use this logical array to index into the original array x , in order to retrieve just the non-NaN values. |
| Markdown | # 
By clicking “Sign up”, you agree to our [terms of service](https://stackoverflow.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://stackoverflow.com/legal/privacy-policy).
# OR
Already have an account? [Log in](https://stackoverflow.com/users/login)
[Skip to main content](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#content)
[Stack Overflow](https://stackoverflow.com/)
1. [About](https://stackoverflow.co/)
2. Products
3. [For Teams](https://stackoverflow.co/teams/)
1. [Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-for-teams)
2. [Advertising Reach devs & technologists worldwide about your product, service or employer brand](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-advertising)
3. [Knowledge Solutions Data licensing offering for businesses to build and improve AI tools and models](https://stackoverflow.co/api-solutions/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=overflow-api)
4. [Labs The future of collective knowledge sharing](https://stackoverflow.co/labs/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=labs)
5. [About the company](https://stackoverflow.co/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=about-the-company) [Visit the blog](https://stackoverflow.blog/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=blog)
1. ### [current community](https://stackoverflow.com/)
- [Stack Overflow](https://stackoverflow.com/)
[help](https://stackoverflow.com/help) [chat](https://chat.stackoverflow.com/?tab=explore)
- [Meta Stack Overflow](https://meta.stackoverflow.com/)
### your communities
[Sign up](https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F11620914%2Fhow-do-i-remove-nan-values-from-a-numpy-array) or [log in](https://stackoverflow.com/users/login?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F11620914%2Fhow-do-i-remove-nan-values-from-a-numpy-array) to customize your list.
### [more stack exchange communities](https://stackexchange.com/sites)
[company blog](https://stackoverflow.blog/)
2. [Log in](https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F11620914%2Fhow-do-i-remove-nan-values-from-a-numpy-array)
3. [Sign up](https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F11620914%2Fhow-do-i-remove-nan-values-from-a-numpy-array)
# Let's set up your homepage Select a few topics you're interested in:
python
javascript
c\#
reactjs
java
android
html
flutter
c++
node.js
typescript
css
r
php
angular
next.js
spring-boot
machine-learning
sql
excel
ios
azure
docker
Or search from our full list:
- javascript
- python
- java
- c\#
- php
- android
- html
- jquery
- c++
- css
- ios
- sql
- mysql
- r
- reactjs
- node.js
- arrays
- c
- asp.net
- json
- python-3.x
- .net
- ruby-on-rails
- sql-server
- swift
- django
- angular
- objective-c
- excel
- pandas
- angularjs
- regex
- typescript
- ruby
- linux
- ajax
- iphone
- vba
- xml
- laravel
- spring
- asp.net-mvc
- database
- wordpress
- string
- flutter
- postgresql
- mongodb
- wpf
- windows
- xcode
- amazon-web-services
- bash
- git
- oracle-database
- spring-boot
- dataframe
- azure
- firebase
- list
- multithreading
- docker
- vb.net
- react-native
- eclipse
- algorithm
- powershell
- macos
- visual-studio
- numpy
- image
- forms
- scala
- function
- vue.js
- performance
- twitter-bootstrap
- selenium
- winforms
- kotlin
- loops
- express
- dart
- hibernate
- sqlite
- matlab
- python-2.7
- shell
- rest
- apache
- entity-framework
- android-studio
- csv
- maven
- linq
- qt
- dictionary
- unit-testing
- asp.net-core
- facebook
- apache-spark
- tensorflow
- file
- swing
- class
- unity-game-engine
- sorting
- date
- authentication
- go
- symfony
- t-sql
- opencv
- matplotlib
- .htaccess
- google-chrome
- for-loop
- datetime
- codeigniter
- perl
- http
- validation
- sockets
- google-maps
- object
- uitableview
- xaml
- oop
- visual-studio-code
- if-statement
- cordova
- ubuntu
- web-services
- email
- android-layout
- github
- spring-mvc
- elasticsearch
- kubernetes
- selenium-webdriver
- ms-access
- ggplot2
- user-interface
- parsing
- pointers
- google-sheets
- c++11
- security
- machine-learning
- google-apps-script
- ruby-on-rails-3
- templates
- flask
- nginx
- variables
- exception
- sql-server-2008
- gradle
- debugging
- tkinter
- delphi
- listview
- jpa
- asynchronous
- web-scraping
- haskell
- pdf
- jsp
- ssl
- amazon-s3
- google-cloud-platform
- jenkins
- testing
- xamarin
- wcf
- batch-file
- generics
- npm
- ionic-framework
- network-programming
- unix
- recursion
- google-app-engine
- mongoose
- visual-studio-2010
- .net-core
- android-fragments
- assembly
- animation
- math
- svg
- session
- rust
- intellij-idea
- hadoop
- curl
- next.js
- join
- winapi
- django-models
- laravel-5
- url
- heroku
- http-redirect
- tomcat
- google-cloud-firestore
- inheritance
- webpack
- image-processing
- gcc
- keras
- swiftui
- asp.net-mvc-4
- logging
- dom
- matrix
- pyspark
- actionscript-3
- button
- post
- optimization
- firebase-realtime-database
- web
- jquery-ui
- cocoa
- xpath
- iis
- d3.js
- javafx
- firefox
- xslt
- internet-explorer
- caching
- select
- asp.net-mvc-3
- opengl
- events
- asp.net-web-api
- plot
- dplyr
- encryption
- magento
- stored-procedures
- search
- amazon-ec2
- ruby-on-rails-4
- memory
- canvas
- audio
- multidimensional-array
- random
- jsf
- vector
- redux
- cookies
- input
- facebook-graph-api
- flash
- indexing
- xamarin.forms
- arraylist
- ipad
- cocoa-touch
- data-structures
- video
- azure-devops
- model-view-controller
- apache-kafka
- serialization
- jdbc
- woocommerce
- razor
- routes
- awk
- servlets
- mod-rewrite
- excel-formula
- beautifulsoup
- filter
- docker-compose
- iframe
- aws-lambda
- design-patterns
- text
- visual-c++
- django-rest-framework
- cakephp
- mobile
- android-intent
- struct
- react-hooks
- methods
- groovy
- mvvm
- ssh
- lambda
- checkbox
- time
- ecmascript-6
- grails
- google-chrome-extension
- installation
- cmake
- sharepoint
- shiny
- spring-security
- jakarta-ee
- plsql
- android-recyclerview
- core-data
- types
- sed
- meteor
- android-activity
- activerecord
- bootstrap-4
- websocket
- graph
- replace
- group-by
- scikit-learn
- vim
- file-upload
- junit
- boost
- memory-management
- sass
- import
- async-await
- deep-learning
- error-handling
- eloquent
- dynamic
- soap
- dependency-injection
- silverlight
- layout
- apache-spark-sql
- charts
- deployment
- browser
- gridview
- svn
- while-loop
- google-bigquery
- vuejs2
- highcharts
- dll
- ffmpeg
- view
- foreach
- makefile
- plugins
- redis
- c\#-4.0
- reporting-services
- jupyter-notebook
- unicode
- merge
- reflection
- https
- server
- google-maps-api-3
- twitter
- oauth-2.0
- extjs
- terminal
- axios
- pip
- split
- cmd
- pytorch
- encoding
- django-views
- collections
- database-design
- hash
- netbeans
- automation
- data-binding
- ember.js
- build
- tcp
- pdo
- sqlalchemy
- apache-flex
- mysqli
- entity-framework-core
- concurrency
- command-line
- spring-data-jpa
- printing
- react-redux
- java-8
- lua
- html-table
- ansible
- neo4j
- jestjs
- service
- parameters
- enums
- material-ui
- flexbox
- module
- promise
- visual-studio-2012
- outlook
- firebase-authentication
- web-applications
- webview
- uwp
- jquery-mobile
- utf-8
- datatable
- python-requests
- parallel-processing
- colors
- drop-down-menu
- scipy
- scroll
- tfs
- hive
- count
- syntax
- ms-word
- twitter-bootstrap-3
- ssis
- fonts
- rxjs
- constructor
- google-analytics
- file-io
- three.js
- paypal
- powerbi
- graphql
- cassandra
- discord
- graphics
- compiler-errors
- gwt
- socket.io
- react-router
- solr
- backbone.js
- url-rewriting
- memory-leaks
- datatables
- nlp
- terraform
- oauth
- datagridview
- drupal
- zend-framework
- oracle11g
- knockout.js
- triggers
- neural-network
- interface
- django-forms
- angular-material
- casting
- jmeter
- google-api
- linked-list
- path
- timer
- arduino
- django-templates
- proxy
- orm
- directory
- windows-phone-7
- parse-platform
- visual-studio-2015
- cron
- conditional-statements
- push-notification
- functional-programming
- primefaces
- pagination
- model
- jar
- xamarin.android
- hyperlink
- uiview
- visual-studio-2013
- vbscript
- google-cloud-functions
- gitlab
- azure-active-directory
- jwt
- download
- swift3
- sql-server-2005
- process
- configuration
- rspec
- pygame
- properties
- combobox
- callback
- windows-phone-8
- linux-kernel
- safari
- scrapy
- permissions
- emacs
- scripting
- clojure
- raspberry-pi
- x86
- scope
- io
- expo
- azure-functions
- compilation
- responsive-design
- mongodb-query
- nhibernate
- angularjs-directive
- request
- bluetooth
- reference
- binding
- dns
- architecture
- 3d
- playframework
- pyqt
- version-control
- discord.js
- doctrine-orm
- package
- f\#
- rubygems
- get
- sql-server-2012
- autocomplete
- tree
- openssl
- datepicker
- kendo-ui
- jackson
- yii
- controller
- grep
- nested
- xamarin.ios
- static
- null
- statistics
- transactions
- datagrid
- active-directory
- dockerfile
- uiviewcontroller
- webforms
- discord.py
- phpmyadmin
- sas
- computer-vision
- notifications
- duplicates
- mocking
- youtube
- pycharm
- yaml
- nullpointerexception
- menu
- blazor
- sum
- plotly
- bitmap
- asp.net-mvc-5
- visual-studio-2008
- yii2
- floating-point
- electron
- css-selectors
- stl
- jsf-2
- android-listview
- time-series
- cryptography
- ant
- hashmap
- character-encoding
- stream
- msbuild
- asp.net-core-mvc
- sdk
- google-drive-api
- jboss
- selenium-chromedriver
- joomla
- devise
- cors
- navigation
- anaconda
- cuda
- background
- frontend
- multiprocessing
- binary
- pyqt5
- camera
- iterator
- linq-to-sql
- mariadb
- onclick
- android-jetpack-compose
- ios7
- microsoft-graph-api
- rabbitmq
- android-asynctask
- tabs
- laravel-4
- amazon-dynamodb
- environment-variables
- insert
- uicollectionview
- linker
- xsd
- coldfusion
- console
- continuous-integration
- upload
- textview
- ftp
- opengl-es
- macros
- operating-system
- mockito
- localization
- formatting
- xml-parsing
- vuejs3
- json.net
- type-conversion
- data.table
- kivy
- timestamp
- integer
- calendar
- segmentation-fault
- android-ndk
- prolog
- drag-and-drop
- char
- crash
- jasmine
- dependencies
- automated-tests
- geometry
- azure-pipelines
- android-gradle-plugin
- itext
- fortran
- sprite-kit
- header
- mfc
- firebase-cloud-messaging
- attributes
- nosql
- format
- nuxt.js
- odoo
- db2
- jquery-plugins
- event-handling
- jenkins-pipeline
- julia
- nestjs
- leaflet
- annotations
- flutter-layout
- keyboard
- postman
- textbox
- arm
- visual-studio-2017
- gulp
- stripe-payments
- libgdx
- synchronization
- timezone
- uikit
- azure-web-app-service
- dom-events
- xampp
- wso2
- crystal-reports
- namespaces
- android-emulator
- swagger
- aggregation-framework
- uiscrollview
- jvm
- google-sheets-formula
- sequelize.js
- chart.js
- com
- snowflake-cloud-data-platform
- subprocess
- geolocation
- webdriver
- html5-canvas
- garbage-collection
- centos
- dialog
- sql-update
- widget
- numbers
- concatenation
- qml
- set
- tuples
- java-stream
- mapreduce
- smtp
- ionic2
- windows-10
- rotation
- android-edittext
- modal-dialog
- spring-data
- nuget
- doctrine
- radio-button
- http-headers
- grid
- sonarqube
- lucene
- xmlhttprequest
- listbox
- switch-statement
- initialization
- internationalization
- components
- apache-camel
- boolean
- google-play
- serial-port
- gdb
- ios5
- ldap
- return
- youtube-api
- pivot
- eclipse-plugin
- latex
- frameworks
- tags
- containers
- github-actions
- c++17
- subquery
- dataset
- asp-classic
- foreign-keys
- label
- embedded
- uinavigationcontroller
- copy
- delegates
- struts2
- google-cloud-storage
- migration
- protractor
- base64
- queue
- find
- uibutton
- sql-server-2008-r2
- arguments
- composer-php
- append
- jaxb
- stack
- zip
- tailwind-css
- cucumber
- autolayout
- ide
- entity-framework-6
- iteration
- popup
- r-markdown
- windows-7
- airflow
- vb6
- g++
- ssl-certificate
- hover
- clang
- jqgrid
- range
- gmail
Next
You’ll be prompted to create an account to view your personalized homepage.
1. 1. [Home](https://stackoverflow.com/)
2. [Questions](https://stackoverflow.com/questions)
3. [AI Assist Labs](https://stackoverflow.ai/)
4. [Tags](https://stackoverflow.com/tags)
5. [Challenges](https://stackoverflow.com/beta/challenges)
6. [Chat](https://chat.stackoverflow.com/rooms/259507/stack-overflow-lobby)
7. [Articles](https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles)
8. [Users](https://stackoverflow.com/users)
9. [Companies](https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav)
10. [Collectives]()
11. Communities for your favorite technologies. [Explore all Collectives](https://stackoverflow.com/collectives-all)
2. Teams

Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
[Try Teams for free](https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) [Explore Teams](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams)
3. [Teams]()
4. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. [Explore Teams](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact)
##### Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
[Learn more about Collectives](https://stackoverflow.com/collectives)
**Teams**
Q\&A for work
Connect and share knowledge within a single location that is structured and easy to search.
[Learn more about Teams](https://stackoverflow.co/teams/)
# 
# Hang on, you can't upvote just yet.
You'll need to complete a few actions and gain 15 reputation points before being able to upvote. **Upvoting** indicates when questions and answers are useful. [What's reputation and how do I get it?](https://stackoverflow.com/help/whats-reputation)
Instead, you can save this post to reference later.
Save this post for later
Not now
# 
# Thanks for your vote! You now have 5 free votes weekly.
Free votes
- count toward the total vote score
- does not give reputation to the author
Continue to help good content that is interesting, well-researched, and useful, rise to the top! To gain full voting privileges, [earn reputation](https://stackoverflow.com/help/whats-reputation).
Got it\!
Go to help center to learn more
# [How do I remove NaN values from a NumPy array?](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array)
[Ask Question](https://stackoverflow.com/questions/ask)
Asked
13 years, 2 months ago
Modified [3 years, 2 months ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array?lastactivity "2022-07-30 05:52:24Z")
Viewed 879k times
This question shows research effort; it is useful and clear
392
Save this question.
Show activity on this post.
How do I remove NaN values from a NumPy array?
```
[1, 2, NaN, 4, NaN, 8] âź¶ [1, 2, 4, 8]
```
- [python](https://stackoverflow.com/questions/tagged/python "show questions tagged 'python'")
- [numpy](https://stackoverflow.com/questions/tagged/numpy "show questions tagged 'numpy'")
- [nan](https://stackoverflow.com/questions/tagged/nan "show questions tagged 'nan'")
[Share](https://stackoverflow.com/q/11620914 "Short permalink to this question")
Share a link to this question
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this question](https://stackoverflow.com/posts/11620914/edit)
Follow
Follow this question to receive notifications
[edited Jul 30, 2022 at 5:36](https://stackoverflow.com/posts/11620914/revisions "show all edits to this post")
[](https://stackoverflow.com/users/365102/mateen-ulhaq)
[Mateen Ulhaq](https://stackoverflow.com/users/365102/mateen-ulhaq)
27\.7k2121 gold badges120120 silver badges155155 bronze badges
asked Jul 23, 2012 at 21:36
[](https://stackoverflow.com/users/1464677/dax-feliz)
[Dax Feliz](https://stackoverflow.com/users/1464677/dax-feliz)Dax Feliz
13k88 gold badges3333 silver badges3434 bronze badges
0
[Add a comment](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array "Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.") \|
## 13 Answers 13
Sorted by:
[Reset to default](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array?answertab=scoredesc#tab-top)
This answer is useful
630
Save this answer.
Show activity on this post.
To remove NaN values from a NumPy array `x`:
```
x = x[~numpy.isnan(x)]
```
##### Explanation
The inner function `numpy.isnan` returns a boolean/logical array which has the value `True` everywhere that `x` is not-a-number. Since we want the opposite, we use the logical-not operator `~` to get an array with `True`s everywhere that `x` **is** a valid number.
Lastly, we use this logical array to index into the original array `x`, in order to retrieve just the non-NaN values.
[Share](https://stackoverflow.com/a/11620982 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/11620982/edit)
Follow
Follow this answer to receive notifications
[edited Jul 30, 2022 at 5:52](https://stackoverflow.com/posts/11620982/revisions "show all edits to this post")
[](https://stackoverflow.com/users/365102/mateen-ulhaq)
[Mateen Ulhaq](https://stackoverflow.com/users/365102/mateen-ulhaq)
27\.7k2121 gold badges120120 silver badges155155 bronze badges
answered Jul 23, 2012 at 21:42
[](https://stackoverflow.com/users/537098/jmetz)
[jmetz](https://stackoverflow.com/users/537098/jmetz)jmetz
12\.9k33 gold badges3232 silver badges4141 bronze badges
Sign up to request clarification or add additional context in comments.
## 10 Comments
Add a comment
[](https://stackoverflow.com/users/7650/miki-tebeka)
Miki Tebeka
[Miki Tebeka](https://stackoverflow.com/users/7650/miki-tebeka)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment15389511_11620982)
Or `x = x[numpy.isfinite(x)]`
2012-07-23T22:29:06.803Z+00:00
53
Reply
- Copy link
[](https://stackoverflow.com/users/424651/chbrown)
chbrown
[chbrown](https://stackoverflow.com/users/424651/chbrown)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment29913880_11620982)
Or `x = x[~numpy.isnan(x)]`, which is equivalent to mutzmatron's original answer, but shorter. In case you want to keep your infinities around, know that `numpy.isfinite(numpy.inf) == False`, of course, but `~numpy.isnan(numpy.inf) == True`.
2013-11-19T19:02:34.14Z+00:00
23
Reply
- Copy link
[](https://stackoverflow.com/users/3765905/boltzmannbrain)
BoltzmannBrain
[BoltzmannBrain](https://stackoverflow.com/users/3765905/boltzmannbrain)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment79136181_11620982)
For people looking to solve this with an ndarray and maintain the dimensions, use [numpy where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html): `np.where(np.isfinite(x), x, 0)`
2017-09-07T02:51:07.263Z+00:00
17
Reply
- Copy link
[](https://stackoverflow.com/users/796919/towry)
towry
[towry](https://stackoverflow.com/users/796919/towry)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment89217800_11620982)
TypeError: only integer scalar arrays can be converted to a scalar index
2018-06-30T14:29:37.237Z+00:00
1
Reply
- Copy link
[](https://stackoverflow.com/users/537098/jmetz)
jmetz
[jmetz](https://stackoverflow.com/users/537098/jmetz)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment89254484_11620982)
@towry: this is happening because your input, `x` is not a numpy array. If you want to use logical indexing, it must be an array - e.g. `x = np.array(x)`
2018-07-02T11:32:48.91Z+00:00
1
Reply
- Copy link
Add a comment
\|
Show 5 more comments
This answer is useful
77
Save this answer.
Show activity on this post.
```
filter(lambda v: v==v, x)
```
works both for lists and numpy array since v!=v only for NaN
[Share](https://stackoverflow.com/a/29679784 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0")
[Improve this answer](https://stackoverflow.com/posts/29679784/edit)
Follow
Follow this answer to receive notifications
answered Apr 16, 2015 at 15:46
[](https://stackoverflow.com/users/209852/udibr)
[udibr](https://stackoverflow.com/users/209852/udibr)udibr
1,08977 silver badges55 bronze badges
## 8 Comments
Add a comment
[](https://stackoverflow.com/users/157441/austin-richardson)
Austin Richardson
[Austin Richardson](https://stackoverflow.com/users/157441/austin-richardson)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment50249119_29679784)
A hack but an especially useful one in the case where you are filtering nans from an array of objects with mixed types, such as a strings and nans.
2015-06-29T14:15:01.693Z+00:00
12
Reply
- Copy link
[](https://stackoverflow.com/users/6260170/chris-rands)
Chris\_Rands
[Chris\_Rands](https://stackoverflow.com/users/6260170/chris-rands)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment90198356_29679784)
This might seem clever, but if obscures the logic and theoretically other objects (such as custom classes) can also have this property
2018-07-31T15:02:58.11Z+00:00
5
Reply
- Copy link
[](https://stackoverflow.com/users/1825043/christian-oreilly)
Christian O'Reilly
[Christian O'Reilly](https://stackoverflow.com/users/1825043/christian-oreilly)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment110324628_29679784)
Also useful because it only needs `x` to be specified once as opposed to solutions of the type `x[~numpy.isnan(x)]`. This is convenient when `x` is defined by a long expression and you don't want to clutter the code by creating a temporary variable to store the result of this long expression.
2020-06-15T01:09:11.307Z+00:00
1
Reply
- Copy link
[](https://stackoverflow.com/users/1795641/smm)
smm
[smm](https://stackoverflow.com/users/1795641/smm)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment112340733_29679784)
It might be slow compere to `x[~numpy.isnan(x)]`
2020-08-21T21:23:10.413Z+00:00
1
Reply
- Copy link
[](https://stackoverflow.com/users/7362806/m-idk392845)
M\_Idk392845
[M\_Idk392845](https://stackoverflow.com/users/7362806/m-idk392845)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment131554252_29679784)
what is v and what is x?
2022-11-21T21:12:32.293Z+00:00
1
Reply
- Copy link
Add a comment
\|
Show 3 more comments
This answer is useful
47
Save this answer.
Show activity on this post.
For me the answer by @jmetz didn't work, however using pandas isnull() did.
```
x = x[~pd.isnull(x)]
```
[Share](https://stackoverflow.com/a/43475189 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0")
[Improve this answer](https://stackoverflow.com/posts/43475189/edit)
Follow
Follow this answer to receive notifications
answered Apr 18, 2017 at 14:37
[](https://stackoverflow.com/users/1772802/daniel-kislyuk)
[Daniel Kislyuk](https://stackoverflow.com/users/1772802/daniel-kislyuk)Daniel Kislyuk
1,0061111 silver badges1212 bronze badges
## 3 Comments
Add a comment
[](https://stackoverflow.com/users/4379906/kbridge4096)
kbridge4096
[kbridge4096](https://stackoverflow.com/users/4379906/kbridge4096)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment128088483_43475189)
or: `x = x[x.notnull()]`
2022-06-05T17:18:56.973Z+00:00
2
Reply
- Copy link
[](https://stackoverflow.com/users/20156987/llohann)
Llohann
[Llohann](https://stackoverflow.com/users/20156987/llohann)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment134949105_43475189)
I am not found of including pandas on the pipe but the accepted solution got me `TypeError: ufunc 'isnan' not supported for the input types`. It does not work with strings or object types. This solution did.
2023-06-23T07:32:03.87Z+00:00
1
Reply
- Copy link
[](https://stackoverflow.com/users/3429115/rafs)
Rafs
[Rafs](https://stackoverflow.com/users/3429115/rafs)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment137524880_43475189)
Added benefit for this one is it removes `NaT`s out of the box
2024-02-16T15:53:31.297Z+00:00
0
Reply
- Copy link
Add a comment
This answer is useful
36
Save this answer.
Show activity on this post.
Try this:
```
import math
print [value for value in x if not math.isnan(value)]
```
For more, read on [List Comprehensions](http://docs.python.org/tutorial/datastructures.html#list-comprehensions).
[Share](https://stackoverflow.com/a/11620945 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0")
[Improve this answer](https://stackoverflow.com/posts/11620945/edit)
Follow
Follow this answer to receive notifications
answered Jul 23, 2012 at 21:39
[](https://stackoverflow.com/users/42610/liori)
[liori](https://stackoverflow.com/users/42610/liori)liori
42\.6k1313 gold badges8080 silver badges111111 bronze badges
## 3 Comments
Add a comment
[](https://stackoverflow.com/users/537098/jmetz)
jmetz
[jmetz](https://stackoverflow.com/users/537098/jmetz)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment15406044_11620945)
If you're using numpy both my answer and that by @lazy1 are almost an order of magnitude faster than the list comprehension - lazy1's solution is slightly faster (though technically will also not return any infinity values).
2012-07-24T13:54:16.493Z+00:00
6
Reply
- Copy link
[](https://stackoverflow.com/users/4684507/hypers)
hypers
[hypers](https://stackoverflow.com/users/4684507/hypers)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment81833136_11620945)
Don't forget the brackets :) `print ([value for value in x if not math.isnan(value)])`
2017-11-22T16:09:35.39Z+00:00
0
Reply
- Copy link
[](https://stackoverflow.com/users/2523501/yeliabsalohcin)
yeliabsalohcin
[yeliabsalohcin](https://stackoverflow.com/users/2523501/yeliabsalohcin)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment93769176_11620945)
If you're using numpy like the top answer then you can use this list comprehension answer with the `np` package: So returns your list without the nans: `[value for value in x if not np.isnan(value)]`
2018-11-23T14:09:28.98Z+00:00
0
Reply
- Copy link
Add a comment
This answer is useful
28
Save this answer.
Show activity on this post.
[@jmetz's answer](https://stackoverflow.com/a/11620982/3645374) is probably the one most people need; however it yields a one-dimensional array, e.g. making it unusable to remove entire rows or columns in matrices.
To do so, one should reduce the logical array to one dimension, then index the target array. For instance, the following will remove rows which have at least one NaN value:
```
x = x[~numpy.isnan(x).any(axis=1)]
```
See more detail [here](https://www.w3resource.com/python-exercises/numpy/python-numpy-exercise-91.php).
[Share](https://stackoverflow.com/a/61589266 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/61589266/edit)
Follow
Follow this answer to receive notifications
answered May 4, 2020 at 9:43
[](https://stackoverflow.com/users/3645374/m4urice)
[M4urice](https://stackoverflow.com/users/3645374/m4urice)M4urice
66111 gold badge99 silver badges1616 bronze badges
## Comments
Add a comment
This answer is useful
10
Save this answer.
Show activity on this post.
As shown by others
```
x[~numpy.isnan(x)]
```
works. But it will throw an error if the numpy dtype is not a native data type, for example if it is object. In that case you can use pandas.
```
x[~pandas.isna(x)] or x[~pandas.isnull(x)]
```
[Share](https://stackoverflow.com/a/47486199 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/47486199/edit)
Follow
Follow this answer to receive notifications
[edited Jan 9, 2020 at 13:55](https://stackoverflow.com/posts/47486199/revisions "show all edits to this post")
[](https://stackoverflow.com/users/1688792/shashank-srivastava)
[Shashank Srivastava](https://stackoverflow.com/users/1688792/shashank-srivastava)
19522 silver badges1313 bronze badges
answered Nov 25, 2017 at 12:55
[](https://stackoverflow.com/users/6248016/koliyat9811)
[koliyat9811](https://stackoverflow.com/users/6248016/koliyat9811)koliyat9811
92511 gold badge1010 silver badges1212 bronze badges
## Comments
Add a comment
This answer is useful
8
Save this answer.
Show activity on this post.
If you're using `numpy`
```
# first get the indices where the values are finite
ii = np.isfinite(x)
# second get the values
x = x[ii]
```
[Share](https://stackoverflow.com/a/48823495 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0")
[Improve this answer](https://stackoverflow.com/posts/48823495/edit)
Follow
Follow this answer to receive notifications
answered Feb 16, 2018 at 9:19
[](https://stackoverflow.com/users/3097391/aloha)
[aloha](https://stackoverflow.com/users/3097391/aloha)aloha
4,83466 gold badges3636 silver badges4343 bronze badges
## Comments
Add a comment
This answer is useful
7
Save this answer.
Show activity on this post.
The [accepted answer](https://stackoverflow.com/a/11620982/7128154) changes shape for 2d arrays. I present a solution here, using the Pandas [dropna()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html) functionality. It works for 1D and 2D arrays. In the 2D case you can choose weather to **drop the row or column** containing `np.nan`.
```
import pandas as pd
import numpy as np
def dropna(arr, *args, **kwarg):
assert isinstance(arr, np.ndarray)
dropped=pd.DataFrame(arr).dropna(*args, **kwarg).values
if arr.ndim==1:
dropped=dropped.flatten()
return dropped
x = np.array([1400, 1500, 1600, np.nan, np.nan, np.nan ,1700])
y = np.array([[1400, 1500, 1600], [np.nan, 0, np.nan] ,[1700,1800,np.nan]] )
print('='*20+' 1D Case: ' +'='*20+'\nInput:\n',x,sep='')
print('\ndropna:\n',dropna(x),sep='')
print('\n\n'+'='*20+' 2D Case: ' +'='*20+'\nInput:\n',y,sep='')
print('\ndropna (rows):\n',dropna(y),sep='')
print('\ndropna (columns):\n',dropna(y,axis=1),sep='')
print('\n\n'+'='*20+' x[np.logical_not(np.isnan(x))] for 2D: ' +'='*20+'\nInput:\n',y,sep='')
print('\ndropna:\n',x[np.logical_not(np.isnan(x))],sep='')
```
**Result:**
```
==================== 1D Case: ====================
Input:
[1400. 1500. 1600. nan nan nan 1700.]
dropna:
[1400. 1500. 1600. 1700.]
==================== 2D Case: ====================
Input:
[[1400. 1500. 1600.]
[ nan 0. nan]
[1700. 1800. nan]]
dropna (rows):
[[1400. 1500. 1600.]]
dropna (columns):
[[1500.]
[ 0.]
[1800.]]
==================== x[np.logical_not(np.isnan(x))] for 2D: ====================
Input:
[[1400. 1500. 1600.]
[ nan 0. nan]
[1700. 1800. nan]]
dropna:
[1400. 1500. 1600. 1700.]
```
[Share](https://stackoverflow.com/a/55194127 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/55194127/edit)
Follow
Follow this answer to receive notifications
answered Mar 16, 2019 at 6:37
[](https://stackoverflow.com/users/7128154/markus-dutschke)
[Markus Dutschke](https://stackoverflow.com/users/7128154/markus-dutschke)Markus Dutschke
10\.7k44 gold badges7272 silver badges6767 bronze badges
## Comments
Add a comment
This answer is useful
7
Save this answer.
Show activity on this post.
In case it helps, for simple 1d arrays:
```
x = np.array([np.nan, 1, 2, 3, 4])
x[~np.isnan(x)]
>>> array([1., 2., 3., 4.])
```
but if you wish to expand to matrices and preserve the shape:
```
x = np.array([
[np.nan, np.nan],
[np.nan, 0],
[1, 2],
[3, 4]
])
x[~np.isnan(x).any(axis=1)]
>>> array([[1., 2.],
[3., 4.]])
```
I encountered this issue when dealing with pandas `.shift()` functionality, and I wanted to avoid using `.apply(..., axis=1)` at all cost due to its inefficiency.
[Share](https://stackoverflow.com/a/66643691 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/66643691/edit)
Follow
Follow this answer to receive notifications
answered Mar 15, 2021 at 18:36
[](https://stackoverflow.com/users/10905753/robin-teuwens)
[Robin Teuwens](https://stackoverflow.com/users/10905753/robin-teuwens)Robin Teuwens
15111 silver badge66 bronze badges
## Comments
Add a comment
This answer is useful
6
Save this answer.
Show activity on this post.
Doing the above :
```
x = x[~numpy.isnan(x)]
```
or
```
x = x[numpy.logical_not(numpy.isnan(x))]
```
I found that resetting to the same variable (x) did not remove the actual nan values and had to use a different variable. Setting it to a different variable removed the nans. e.g.
```
y = x[~numpy.isnan(x)]
```
[Share](https://stackoverflow.com/a/38001353 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0")
[Improve this answer](https://stackoverflow.com/posts/38001353/edit)
Follow
Follow this answer to receive notifications
answered Jun 23, 2016 at 20:35
[](https://stackoverflow.com/users/6506193/melissaou)
[melissaOu](https://stackoverflow.com/users/6506193/melissaou)melissaOu
6111 silver badge22 bronze badges
## 1 Comment
Add a comment
[](https://stackoverflow.com/users/537098/jmetz)
jmetz
[jmetz](https://stackoverflow.com/users/537098/jmetz)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment73084197_38001353)
This is strange; according to [the docs](https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing), boolean array indexing (which this is), is under **advanced indexing** which apparently "always returns a copy of the data", so you should be over-writing `x` with the new value (i.e. without the NaNs...). Can you provide any more info as to why this could be happening?
2017-03-24T10:35:03.27Z+00:00
0
Reply
- Copy link
This answer is useful
2
Save this answer.
Show activity on this post.
Simply fill with
```
x = numpy.array([
[0.99929941, 0.84724713, -0.1500044],
[-0.79709026, numpy.NaN, -0.4406645],
[-0.3599013, -0.63565744, -0.70251352]])
x[numpy.isnan(x)] = .555
print(x)
# [[ 0.99929941 0.84724713 -0.1500044 ]
# [-0.79709026 0.555 -0.4406645 ]
# [-0.3599013 -0.63565744 -0.70251352]]
```
[Share](https://stackoverflow.com/a/65355087 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/65355087/edit)
Follow
Follow this answer to receive notifications
[edited Dec 18, 2020 at 10:59](https://stackoverflow.com/posts/65355087/revisions "show all edits to this post")
answered Dec 18, 2020 at 10:08
[](https://stackoverflow.com/users/13740191/bitbang)
[bitbang](https://stackoverflow.com/users/13740191/bitbang)bitbang
2,2721818 silver badges2020 bronze badges
## Comments
Add a comment
This answer is useful
1
Save this answer.
Show activity on this post.
pandas introduces an option to convert all data types to missing values.
- <https://pandas.pydata.org/docs/user_guide/missing_data.html>
The `np.isnan()` function is not compatible with all data types, e.g.
```
>>> import numpy as np
>>> values = [np.nan, "x", "y"]
>>> np.isnan(values)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
```
The `pd.isna()` and `pd.notna()` functions are compatible with many data types and pandas introduces a `pd.NA` value:
```
>>> import numpy as np
>>> import pandas as pd
>>> values = pd.Series([np.nan, "x", "y"])
>>> values
0 NaN
1 x
2 y
dtype: object
>>> values.loc[pd.isna(values)]
0 NaN
dtype: object
>>> values.loc[pd.isna(values)] = pd.NA
>>> values.loc[pd.isna(values)]
0 <NA>
dtype: object
>>> values
0 <NA>
1 x
2 y
dtype: object
#
# using map with lambda, or a list comprehension
#
>>> values = [np.nan, "x", "y"]
>>> list(map(lambda x: pd.NA if pd.isna(x) else x, values))
[<NA>, 'x', 'y']
>>> [pd.NA if pd.isna(x) else x for x in values]
[<NA>, 'x', 'y']
```
[Share](https://stackoverflow.com/a/72293751 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0")
[Improve this answer](https://stackoverflow.com/posts/72293751/edit)
Follow
Follow this answer to receive notifications
[edited May 19, 2022 at 16:50](https://stackoverflow.com/posts/72293751/revisions "show all edits to this post")
answered May 18, 2022 at 17:43
[](https://stackoverflow.com/users/1172685/darren-weber)
[Darren Weber](https://stackoverflow.com/users/1172685/darren-weber)Darren Weber
1,71411 gold badge2121 silver badges2222 bronze badges
## Comments
Add a comment
This answer is useful
\-2
Save this answer.
Show activity on this post.
A simplest way is:
```
numpy.nan_to_num(x)
```
Documentation: <https://docs.scipy.org/doc/numpy/reference/generated/numpy.nan_to_num.html>
[Share](https://stackoverflow.com/a/44683212 "Short permalink to this answer")
Share a link to this answer
Copy link
[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0")
[Improve this answer](https://stackoverflow.com/posts/44683212/edit)
Follow
Follow this answer to receive notifications
answered Jun 21, 2017 at 18:03
[](https://stackoverflow.com/users/8195855/bruno-rodrigues-de-oliveira)
[Bruno Rodrigues de Oliveira](https://stackoverflow.com/users/8195855/bruno-rodrigues-de-oliveira)Bruno Rodrigues de Oliveira
4522 bronze badges
## 1 Comment
Add a comment
[](https://stackoverflow.com/users/4211279/pier-paolo)
Pier Paolo
[Pier Paolo](https://stackoverflow.com/users/4211279/pier-paolo)
[Over a year ago](https://stackoverflow.com/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array#comment76352149_44683212)
Welcome to SO! The solution you propose does not answer the problem: your solution substitutes `NaN`s with a large number, while the OP asked to entirely remove the elements.
2017-06-21T18:49:31.223Z+00:00
6
Reply
- Copy link
**[Protected question](https://stackoverflow.com/help/privileges/protect-questions)**. To answer this question, you need to have at least 10 reputation on this site (not counting the [association bonus](https://meta.stackexchange.com/questions/141648/what-is-the-association-bonus-and-how-does-it-work)). The reputation requirement helps protect this question from spam and non-answer activity.
Start asking to get answers
Find the answer to your question by asking.
[Ask question](https://stackoverflow.com/questions/ask)
Explore related questions
- [python](https://stackoverflow.com/questions/tagged/python "show questions tagged 'python'")
- [numpy](https://stackoverflow.com/questions/tagged/numpy "show questions tagged 'numpy'")
- [nan](https://stackoverflow.com/questions/tagged/nan "show questions tagged 'nan'")
See similar questions with these tags.
- The Overflow Blog
- [One is not the loneliest number for API calls](https://stackoverflow.blog/2025/10/03/one-is-not-the-loneliest-number-for-api-calls/?cb=1)
- [Context is king for secure, AI-generated code](https://stackoverflow.blog/2025/10/07/context-is-king-for-secure-ai-generated-code/?cb=1)
- Featured on Meta
- [Please welcome V2Blast back to the Community Team\!](https://meta.stackexchange.com/questions/412987/please-welcome-v2blast-back-to-the-community-team?cb=1)
- [A First Look: Stack Overflow Redesign](https://meta.stackexchange.com/questions/412992/a-first-look-stack-overflow-redesign?cb=1)
- [Policy: Generative AI (e.g., ChatGPT) is banned](https://meta.stackoverflow.com/questions/421831/policy-generative-ai-e-g-chatgpt-is-banned?cb=1)
- [Exploring new types of questions on Stack Overflow](https://meta.stackoverflow.com/questions/435121/exploring-new-types-of-questions-on-stack-overflow?cb=1)
Community activity
Last 1 hr
- Users online activity
21253 users online
- 29 questions
- 16 answers
- 96 comments
- 403 upvotes
Popular tags
[c++](https://stackoverflow.com/questions/tagged/c++)[python](https://stackoverflow.com/questions/tagged/python)[java](https://stackoverflow.com/questions/tagged/java)[git](https://stackoverflow.com/questions/tagged/git)[javascript](https://stackoverflow.com/questions/tagged/javascript)[mysql](https://stackoverflow.com/questions/tagged/mysql)
Popular unanswered question
[Error occured while running DAX in Power BI which is connected to SSAS using live connect mode](https://stackoverflow.com/questions/79784495)
[powerbi](https://stackoverflow.com/questions/tagged/powerbi)[dax](https://stackoverflow.com/questions/tagged/dax)[ssas](https://stackoverflow.com/questions/tagged/ssas)[powerbi-desktop](https://stackoverflow.com/questions/tagged/powerbi-desktop)[ssas-tabular](https://stackoverflow.com/questions/tagged/ssas-tabular)
[](https://stackoverflow.com/users/10433098)
[user10433098](https://stackoverflow.com/users/10433098)
- 1
2 hours ago
#### Linked
[4](https://stackoverflow.com/questions/42387613/delete-nan-or-reduce-length-of-numpy-array-if-array-contains-nan-after-convert?lq=1 "Question score (upvotes - downvotes)")
[delete 'nan' or reduce length of numpy array if array contains nan after converting to numpy from pandas](https://stackoverflow.com/questions/42387613/delete-nan-or-reduce-length-of-numpy-array-if-array-contains-nan-after-convert?noredirect=1&lq=1)
[1](https://stackoverflow.com/questions/70982172/remove-all-nan-from-nested-list?lq=1 "Question score (upvotes - downvotes)")
[Remove all nan from nested list](https://stackoverflow.com/questions/70982172/remove-all-nan-from-nested-list?noredirect=1&lq=1)
[0](https://stackoverflow.com/questions/73092858/removing-nan-from-an-string-array-within-a-dictionary?lq=1 "Question score (upvotes - downvotes)")
[Removing nan from an string array within a dictionary](https://stackoverflow.com/questions/73092858/removing-nan-from-an-string-array-within-a-dictionary?noredirect=1&lq=1)
[\-1](https://stackoverflow.com/questions/71052293/how-to-remove-nan-values-from-a-list-of-values-inside-a-variable-in-python?lq=1 "Question score (upvotes - downvotes)")
[How to remove nan values from a list of values inside a variable in Python?](https://stackoverflow.com/questions/71052293/how-to-remove-nan-values-from-a-list-of-values-inside-a-variable-in-python?noredirect=1&lq=1)
[0](https://stackoverflow.com/questions/75422549/i-am-trying-to-fit-my-data-for-linear-regression-and-getting-this-error?lq=1 "Question score (upvotes - downvotes)")
[I am trying to fit my data for Linear Regression and getting this error](https://stackoverflow.com/questions/75422549/i-am-trying-to-fit-my-data-for-linear-regression-and-getting-this-error?noredirect=1&lq=1)
[0](https://stackoverflow.com/questions/57694334/removing-nans-from-imported-lists?lq=1 "Question score (upvotes - downvotes)")
[Removing NaNs from imported lists](https://stackoverflow.com/questions/57694334/removing-nans-from-imported-lists?noredirect=1&lq=1)
[380](https://stackoverflow.com/questions/15998188/how-can-i-obtain-the-element-wise-logical-not-of-a-pandas-series?lq=1 "Question score (upvotes - downvotes)")
[How can I obtain the element-wise logical NOT of a pandas Series?](https://stackoverflow.com/questions/15998188/how-can-i-obtain-the-element-wise-logical-not-of-a-pandas-series?noredirect=1&lq=1)
[63](https://stackoverflow.com/questions/13600988/python-tilde-unary-operator-as-negation-numpy-bool-array?lq=1 "Question score (upvotes - downvotes)")
[python tilde unary operator as negation numpy bool array](https://stackoverflow.com/questions/13600988/python-tilde-unary-operator-as-negation-numpy-bool-array?noredirect=1&lq=1)
[11](https://stackoverflow.com/questions/36957149/density-map-heatmaps-in-matplotlib?lq=1 "Question score (upvotes - downvotes)")
[Density map (heatmaps) in matplotlib](https://stackoverflow.com/questions/36957149/density-map-heatmaps-in-matplotlib?noredirect=1&lq=1)
[9](https://stackoverflow.com/questions/15754333/draw-create-scatterplots-of-datasets-with-nan?lq=1 "Question score (upvotes - downvotes)")
[Draw / Create Scatterplots of datasets with NaN](https://stackoverflow.com/questions/15754333/draw-create-scatterplots-of-datasets-with-nan?noredirect=1&lq=1)
[See more linked questions](https://stackoverflow.com/questions/linked/11620914?lq=1)
#### Related
[0](https://stackoverflow.com/questions/25026486/removing-nan-elements-from-matrix?rq=3 "Question score (upvotes - downvotes)")
[Removing nan elements from matrix](https://stackoverflow.com/questions/25026486/removing-nan-elements-from-matrix?rq=3)
[6](https://stackoverflow.com/questions/29120626/removing-nans-in-numpy-arrays?rq=3 "Question score (upvotes - downvotes)")
[Removing NaNs in numpy arrays](https://stackoverflow.com/questions/29120626/removing-nans-in-numpy-arrays?rq=3)
[9](https://stackoverflow.com/questions/29438329/removing-nans-from-numpy-2-d-arrays?rq=3 "Question score (upvotes - downvotes)")
[Removing NAN's from numpy 2-D arrays](https://stackoverflow.com/questions/29438329/removing-nans-from-numpy-2-d-arrays?rq=3)
[1](https://stackoverflow.com/questions/38753198/how-can-i-remove-rows-from-a-numpy-array-that-have-nan-as-the-first-element?rq=3 "Question score (upvotes - downvotes)")
[How can I remove rows from a numpy array that have NaN as the first element?](https://stackoverflow.com/questions/38753198/how-can-i-remove-rows-from-a-numpy-array-that-have-nan-as-the-first-element?rq=3)
[3](https://stackoverflow.com/questions/42041037/removing-nan-values-from-a-python-list?rq=3 "Question score (upvotes - downvotes)")
[Removing nan values from a Python List](https://stackoverflow.com/questions/42041037/removing-nan-values-from-a-python-list?rq=3)
[2](https://stackoverflow.com/questions/47138318/removing-nan-values-from-a-numpy-array?rq=3 "Question score (upvotes - downvotes)")
[Removing "nan" values from a numpy array](https://stackoverflow.com/questions/47138318/removing-nan-values-from-a-numpy-array?rq=3)
[1](https://stackoverflow.com/questions/48101388/remove-nans-in-multidimensional-array?rq=3 "Question score (upvotes - downvotes)")
[Remove nans in multidimensional array](https://stackoverflow.com/questions/48101388/remove-nans-in-multidimensional-array?rq=3)
[0](https://stackoverflow.com/questions/58797635/how-to-remove-nan-values-from-numpy-ndarray?rq=3 "Question score (upvotes - downvotes)")
[How to remove nan values from numpy.ndarray](https://stackoverflow.com/questions/58797635/how-to-remove-nan-values-from-numpy-ndarray?rq=3)
[0](https://stackoverflow.com/questions/60576953/removing-rows-and-columns-with-only-nan-from-numpy-array?rq=3 "Question score (upvotes - downvotes)")
[Removing rows and columns with only NaN from numpy array](https://stackoverflow.com/questions/60576953/removing-rows-and-columns-with-only-nan-from-numpy-array?rq=3)
[2](https://stackoverflow.com/questions/66936375/how-to-remove-nan-from-numpy-subarray?rq=3 "Question score (upvotes - downvotes)")
[how to remove NaN from numpy subarray](https://stackoverflow.com/questions/66936375/how-to-remove-nan-from-numpy-subarray?rq=3)
#### [Hot Network Questions](https://stackexchange.com/questions?tab=hot)
- [JFET amplifier clipping on positive peaks after increasing VCC from 9 V to 24 V — lost headroom on top of sine wave](https://electronics.stackexchange.com/questions/756602/jfet-amplifier-clipping-on-positive-peaks-after-increasing-vcc-from-9-v-to-24-v)
- [Why is it impossible for two orbiting black holes to recede like the Earth–Moon system?](https://physics.stackexchange.com/questions/860377/why-is-it-impossible-for-two-orbiting-black-holes-to-recede-like-the-earth-moon)
- [Who said “Is it lawful to heal on the Sabbath”, Jesus or the Pharisee?](https://hermeneutics.stackexchange.com/questions/108674/who-said-is-it-lawful-to-heal-on-the-sabbath-jesus-or-the-pharisee)
- [Query about circuits containing BJT and Zener Diode](https://electronics.stackexchange.com/questions/756592/query-about-circuits-containing-bjt-and-zener-diode)
- [If gravity bends spacetime, why don’t we detect time dilation gradients inside large objects like Earth?](https://physics.stackexchange.com/questions/860331/if-gravity-bends-spacetime-why-don-t-we-detect-time-dilation-gradients-inside-l)
- [Is the number system for x assumed beforehand when proving the quadratic formula?](https://math.stackexchange.com/questions/5100301/is-the-number-system-for-x-assumed-beforehand-when-proving-the-quadratic-formula)
- [Naming malonic acid derivatives](https://chemistry.stackexchange.com/questions/191018/naming-malonic-acid-derivatives)
- [Most symmetrical tangram](https://puzzling.stackexchange.com/questions/133487/most-symmetrical-tangram)
- [How can I measure power supply noise and ripple lower than 100µV?](https://electronics.stackexchange.com/questions/756583/how-can-i-measure-power-supply-noise-and-ripple-lower-than-100%C2%B5v)
- [When did people start using open bookshelves or bookcases without doors?](https://history.stackexchange.com/questions/79485/when-did-people-start-using-open-bookshelves-or-bookcases-without-doors)
- [Fourier coefficients of time-scaled signal](https://dsp.stackexchange.com/questions/98312/fourier-coefficients-of-time-scaled-signal)
- [Find paths between two vertices without repeating edges but allowing vertex revisits](https://mathematica.stackexchange.com/questions/315602/find-paths-between-two-vertices-without-repeating-edges-but-allowing-vertex-revi)
- [How is homology "weaker than" homotopy?](https://math.stackexchange.com/questions/5100250/how-is-homology-weaker-than-homotopy)
- [Get early versions of gzip](https://retrocomputing.stackexchange.com/questions/32128/get-early-versions-of-gzip)
- [Are IPv6 privacy extensions enabled by default in 24.04 and 25.04?](https://askubuntu.com/questions/1556988/are-ipv6-privacy-extensions-enabled-by-default-in-24-04-and-25-04)
- [Only one hypothesis?](https://stats.stackexchange.com/questions/670632/only-one-hypothesis)
- [Does car Wax paste contain any abrasive polishing components? as i am seeking a 100% pure wax for paint protection](https://mechanics.stackexchange.com/questions/99568/does-car-wax-paste-contain-any-abrasive-polishing-components-as-i-am-seeking-a)
- [Why do we consider there to be gaps between rational numbers, and not between real numbers?](https://math.stackexchange.com/questions/5100356/why-do-we-consider-there-to-be-gaps-between-rational-numbers-and-not-between-re)
- [Does the pronunciation of the -ig ending in German adjectives change in comparative and superlative forms?](https://german.stackexchange.com/questions/80772/does-the-pronunciation-of-the-ig-ending-in-german-adjectives-change-in-comparat)
- [Why are some forms of order more likely than others in the universe?](https://philosophy.stackexchange.com/questions/130949/why-are-some-forms-of-order-more-likely-than-others-in-the-universe)
- [How to modify the command \\@maketitle defined using '\\def' in 'book.cls' in 'main.tex'?](https://tex.stackexchange.com/questions/752067/how-to-modify-the-command-maketitle-defined-using-def-in-book-cls-in-mai)
- [Why do ion thrusters achieve high efficiency despite producing such low thrust?](https://space.stackexchange.com/questions/69976/why-do-ion-thrusters-achieve-high-efficiency-despite-producing-such-low-thrust)
- [Does a continuous map from a 2-sphere into a 2-torus always equate some antipodal points?](https://math.stackexchange.com/questions/5100289/does-a-continuous-map-from-a-2-sphere-into-a-2-torus-always-equate-some-antipoda)
- [Delta method measurbility question](https://stats.stackexchange.com/questions/670590/delta-method-measurbility-question)
[Question feed](https://stackoverflow.com/feeds/question/11620914 "Feed of this question and its answers")
# Subscribe to RSS
Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-py
# Why are you flagging this comment?
Probable spam.
This comment promotes a product, service or website while [failing to disclose the author's affiliation](https://stackoverflow.com/help/promotion).
Unfriendly or contains harassment/bigotry/abuse.
This comment is unkind, insulting or attacks another person or group. Learn more in our [Code of Conduct](https://stackoverflow.com/conduct/abusive-behavior).
Not needed.
This comment is not relevant to the post.
```
```
Enter at least 6 characters
Something else.
A problem not listed above. Try to be as specific as possible.
```
```
Enter at least 6 characters
Flag comment
Cancel
You have 0 flags left today
##### [Stack Overflow](https://stackoverflow.com/)
- [Questions](https://stackoverflow.com/questions)
- [Help](https://stackoverflow.com/help)
- [Chat](https://chat.stackoverflow.com/?tab=explore)
##### [Products](https://stackoverflow.co/)
- [Teams](https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams)
- [Advertising](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising)
- [Talent](https://stackoverflow.co/advertising/employer-branding/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=talent)
##### [Company](https://stackoverflow.co/)
- [About](https://stackoverflow.co/)
- [Press](https://stackoverflow.co/company/press/)
- [Work Here](https://stackoverflow.co/company/work-here/)
- [Legal](https://stackoverflow.com/legal)
- [Privacy Policy](https://stackoverflow.com/legal/privacy-policy)
- [Terms of Service](https://stackoverflow.com/legal/terms-of-service/public)
- [Contact Us](https://stackoverflow.com/contact)
- Cookie Settings
- [Cookie Policy](https://policies.stackoverflow.co/stack-overflow/cookie-policy)
##### [Stack Exchange Network](https://stackexchange.com/)
- [Technology](https://stackexchange.com/sites#technology)
- [Culture & recreation](https://stackexchange.com/sites#culturerecreation)
- [Life & arts](https://stackexchange.com/sites#lifearts)
- [Science](https://stackexchange.com/sites#science)
- [Professional](https://stackexchange.com/sites#professional)
- [Business](https://stackexchange.com/sites#business)
- [API](https://api.stackexchange.com/)
- [Data](https://data.stackexchange.com/)
- [Blog](https://stackoverflow.blog/?blb=1)
- [Facebook](https://www.facebook.com/officialstackoverflow/)
- [Twitter](https://twitter.com/stackoverflow)
- [LinkedIn](https://linkedin.com/company/stack-overflow)
- [Instagram](https://www.instagram.com/thestackoverflow)
Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under [CC BY-SA](https://stackoverflow.com/help/licensing) . rev 2025.10.6.34876 |
| Readable Markdown | null |
| Shard | 169 (laksa) |
| Root Hash | 714406497480128969 |
| Unparsed URL | com,stackoverflow!/questions/11620914/how-do-i-remove-nan-values-from-a-numpy-array s443 |