nan

pylab histogram get rid of nan

天涯浪子 提交于 2019-11-30 17:28:24
I have a problem with making a histogram when some of my data contains "not a number" values. I can get rid of the error by using nan_to_num from numpy, but than i get a lot of zero values which mess up the histogram as well. pylab.figure() pylab.hist(numpy.nan_to_num(A)) pylab.show() So the idea would be to make another array in which all the nan values are gone, or to just mask them in the histogram in some way (preferrably with some builtin method). Remove np.nan values from your array using A[~np.isnan(A)] , this will select all entries in A which values are not nan , so they will be

Pandas: Why is default column type for numeric float?

时光毁灭记忆、已成空白 提交于 2019-11-30 15:30:00
问题 I am using Pandas 0.18.1 with python 2.7.x. I have an empty dataframe that I read first. I see that the types of these columns are object which is OK. When I assign one row of data, the type for numeric values changes to float64 . I was expecting int or int64 . Why does this happen? Is there a way to set some global option to let Pandas knows that for numeric values, treat them by default as int unless the data has a . ? For example, [0 1.0, 2.] , first column is int but other two are float64

python nan != nan

守給你的承諾、 提交于 2019-11-30 14:38:58
Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = float('nan') >>> id(x) == id(x) True >>> x == x False I'm interested in how nan != nan in python. And just to clarify, I know nan is supposed to behave like that by definition, I'm asking about how not about why. Where is that implemented? Is there any other object which behaves like that? For the "where" part of your questions, look starting at line 391 in Objects/floatobject.c in the Python 2.7.3 source tree. A brief discussion is given about the

Double.IsNaN test 100 times faster?

只愿长相守 提交于 2019-11-30 14:27:30
问题 I found this in the .NET Source Code: It claims to be 100 times faster than System.Double.IsNaN . Is there a reason to not use this function instead of System.Double.IsNaN ? [StructLayout(LayoutKind.Explicit)] private struct NanUnion { [FieldOffset(0)] internal double DoubleValue; [FieldOffset(0)] internal UInt64 UintValue; } // The standard CLR double.IsNaN() function is approximately 100 times slower than our own wrapper, // so please make sure to use DoubleUtil.IsNaN() in performance

Is there a better way of making numpy.argmin() ignore NaN values

冷暖自知 提交于 2019-11-30 11:38:12
I want to get the index of the min value of a numpy array that contains NaNs and I want them ignored >>> a = array([ nan, 2.5, 3., nan, 4., 5.]) >>> a array([ NaN, 2.5, 3. , NaN, 4. , 5. ]) if I run argmin, it returns the index of the first NaN >>> a.argmin() 0 I substitute NaNs with Infs and then run argmin >>> a[isnan(a)] = Inf >>> a array([ Inf, 2.5, 3. , Inf, 4. , 5. ]) >>> a.argmin() 1 My dilemma is the following: I'd rather not change NaNs to Infs and then back after I'm done with argmin (since NaNs have a meaning later on in the code). Is there a better way to do this? There is also a

Why can itertools.groupby group the NaNs in lists but not in numpy arrays

北战南征 提交于 2019-11-30 11:20:22
I'm having a difficult time to debug a problem in which the float nan in a list and nan in a numpy.array are handled differently when these are used in itertools.groupby : Given the following list and array: from itertools import groupby import numpy as np lst = [np.nan, np.nan, np.nan, 0.16, 1, 0.16, 0.9999, 0.0001, 0.16, 0.101, np.nan, 0.16] arr = np.array(lst) When I iterate over the list the contiguous nan s are grouped: >>> for key, group in groupby(lst): ... if np.isnan(key): ... print(key, list(group), type(key)) nan [nan, nan, nan] <class 'float'> nan [nan] <class 'float'> However if I

How do I get a summary count of missing/NaN data by column in 'pandas'?

烂漫一生 提交于 2019-11-30 10:47:32
问题 In R I can quickly see a count of missing data using the summary command, but the equivalent pandas DataFrame method, describe does not report these values. I gather I can do something like len(mydata.index) - mydata.count() to compute the number of missing values for each column, but I wonder if there's a better idiom (or if my approach is even right). 回答1: Both describe and info report the count of non-missing values. In [1]: df = DataFrame(np.random.randn(10,2)) In [2]: df.iloc[3:6,0] = np

Counting the number of non-NaN elements in a numpy ndarray in Python

一世执手 提交于 2019-11-30 10:26:53
问题 I need to calculate the number of non-NaN elements in a numpy ndarray matrix. How would one efficiently do this in Python? Here is my simple code for achieving this: import numpy as np def numberOfNonNans(data): count = 0 for i in data: if not np.isnan(i): count += 1 return count Is there a built-in function for this in numpy? Efficiency is important because I'm doing Big Data analysis. Thnx for any help! 回答1: np.count_nonzero(~np.isnan(data)) ~ inverts the boolean matrix returned from np

What do these three special floating-point values mean: positive infinity, negative infinity, NaN?

我的未来我决定 提交于 2019-11-30 09:00:36
How can we use them in our codes, and what will cause NaN(not a number)? Cameron This may be a good reference if you want to learn more about floating point numbers in Java. Positive Infinity is a positive number so large that it can't be represented normally. Negative Infinity is a negative number so large that it cannot be represented normally. NaN means "Not a Number" and results from a mathematical operation that doesn't yield a number- like dividing 0 by 0. In Java, the Double and Float classes both have constants to represent all three cases. They are POSITIVE_INFINITY, NEGATIVE_INFINITY

HTML5 Audio Player Duration Showing Nan

蹲街弑〆低调 提交于 2019-11-30 08:29:17
I just started to learn HTML5 and was going through HTML5 Audio player using JQuery. I coded a player with Playlist, everything works fine except the Duration with help of which my input range slider doesn't works. When I debugged I found that my duration is showing me NAN. I am setting the duration after the song is initialized. Here is my JS code jQuery(document).ready(function() { container = $('.container'); playList = $('#playlist'); playListSong = $('#playlist li'); cover = $('.cover'); play = $('#play'); pause = $('#pause'); mute = $('#mute'); muted = $('#muted'); close = $('#close');