Tell me more ×  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?
share|improve this question add comment  2 Answers  up vote 9
down vote accepted  If you're using numpy for your arrays, you
can also use  x = x[numpy.logical_not(numpy.isnan(x))]
share|improve this answer Or x = x[numpy.isfinite(x)] –  lazy1
Jul 23 '12 at 22:29 These both work! I'm so glad there are so
many ways to do this. Thank you! –  Dax Feliz Jul 23 '12 at
22:47 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. – 
chbrown Nov 19 at 19:02 @dax-felizv I agree with @chbrown, NaN
and Infinite are not the same in numpy. @chbrown - thanks for
pointing out the shorthand for logical_n