从数组中删除NaN值 [英] Removing nan values from an array

查看:2525
本文介绍了从数组中删除NaN值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何从我的数组中删除NaN值。它看起来是这样的:

I want to figure out how to remove nan values from my array. It looks something like this:

x = [1400, 1500, 1600, nan, nan, nan ,1700] #Not in this exact configuration

我是比较新的蟒蛇,所以我还在学习。任何提示?

I'm relatively new to python so I'm still learning. Any tips?

推荐答案

如果您正在使用numpy的为你的阵列,也可以使用

If you're using numpy for your arrays, you can also use

x = x[numpy.logical_not(numpy.isnan(x))]

等价

x = x[~numpy.isnan(x)]

[感谢chbrown为添加的速记]

[Thanks to chbrown for the added shorthand]

这篇关于从数组中删除NaN值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆