nan

Will “min to max” uniform real distribution produce Inf,-Inf, or NaN?

陌路散爱 提交于 2019-12-07 02:55:10
问题 If I were to produce floating point values in the following way: template <typename T> T RandomFromRange(T low, T high){ std::random_device random_device; std::mt19937 engine{random_device()}; std::uniform_real_distribution<T> dist(low, high); return dist(engine); } template <typename T> T GetRandom(){ return RandomFromRange (std::numeric_limits<T>::min(),std::numeric_limits<T>::max()); } //produce floating point values: auto num1 = GetRandom<float>(); auto num2 = GetRandom<float>(); auto

Why does testing `NaN == NaN` not work for dropping from a pandas dataFrame?

早过忘川 提交于 2019-12-07 01:02:25
问题 Please explain how NaN's are treated in pandas because the following logic seems "broken" to me, I tried various ways (shown below) to drop the empty values. My dataframe, which I load from a CSV file using read.csv , has a column comments , which is empty most of the time. The column marked_results.comments looks like this; all the rest of the column is NaN, so pandas loads empty entries as NaNs, so far so good: 0 VP 1 VP 2 VP 3 TEST 4 NaN 5 NaN .... Now I try to drop those entries, only

Comparing pandas Series for equality when they contain nan?

淺唱寂寞╮ 提交于 2019-12-07 00:50:06
问题 My application needs to compare Series instances that sometimes contain nans. That causes ordinary comparison using == to fail, since nan != nan : import numpy as np from pandas import Series s1 = Series([1,np.nan]) s2 = Series([1,np.nan]) >>> (Series([1, nan]) == Series([1, nan])).all() False What's the proper way to compare such Series? 回答1: How about this. First check the NaNs are in the same place (using isnull): In [11]: s1.isnull() Out[11]: 0 False 1 True dtype: bool In [12]: s1.isnull(

Set all NaN elements in sparse matrix to zero

放肆的年华 提交于 2019-12-06 23:07:24
What's the equivalent of the Matlab statement X(isnan(X))=0 in R? Note X is of type of matrix.csr in R. (This is from pkg:SparseM.) Are you sure you want to use the matrix.csr class? It is from the SparseM package and as far as I can tell, at least from the package documentation, there are no is.na<- or is.na[ methods. The Matrix-package does document is.na-methods: > library(Matrix);M <- Matrix(1:6, nrow=4, ncol=3, + dimnames = list(c("a", "b", "c", "d"), c("A", "B", "C"))) > stopifnot(all(!is.na(M))) > M[2:3,2] <- NA > M[is.na(M)] <- 0 > M 4 x 3 Matrix of class "dgeMatrix" A B C a 1 5 3 b 2

Math.Max vs Enumerable.Max

心已入冬 提交于 2019-12-06 22:32:22
问题 Jon Skeet reports today (source) that : Math.Max(1f, float.NaN) == NaN new[] { 1f, float.NaN }.Max() == 1f Why? Edit: same issue with double also! 回答1: As others have posted, I tweeted one sort of "why" - in that it's using IComparable as documented. That just leads to another "why" though. In particular: Console.WriteLine(Math.Max(0, float.NaN)); // Prints NaN Console.WriteLine(0f.CompareTo(float.NaN)); // Prints 1 The first line suggests that NaN is regarded as being greater than 0. The

SSRS Formula or expression to change NaN to 0

自闭症网瘾萝莉.ら 提交于 2019-12-06 22:14:07
问题 I am using the following expression to work out a percentage: =Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name") Days.Value is showing as 0 however in a few of my results instead of reading 0% in my percentage column it is actually reading NaN (Not a Number). Does anyone know the exact expression forumla i need and where I should paste it in my current expression to say "Where NaN is showing, put a '0' instead?" (See image) 回答1: How about =IIF(Fields!Days.Value > 0,Fields!Days.Value

How to output last column element of NumPy 2D array ignoring nan in Python?

我与影子孤独终老i 提交于 2019-12-06 21:18:29
I have a NumPy 2D array as shown below: data.dat X1 X2 X3 X4 1 1 1 1 2 2 4 2 3 3 9 3 4 4 16 4 5 5 25 5 6 6 36 6 7 nan 49 7 8 nan 64 8 9 nan 81 nan 10 nan nan nan Now how do I output the last element of each column ignoring nan in the array. I tried without success the code: A[~np.isnan(A)][-1] Code used import numpy as np with open('data.dat', "r") as data: while True: line = data.readline() if not line.startswith('#'): break data_header = [i for i in line.strip().split('\t') if i] A = np.genfromtxt('data.dat', names = data_header, dtype = float, delimiter = '\t') If A were a plain NumPy array

Number.isNaN doesn't exist in IE

♀尐吖头ヾ 提交于 2019-12-06 17:27:11
问题 Why does not IE support the Number.isNaN function? I can't use simple isNan instead of Number.isNaN 'cause these functions are different! For example: Number.isNaN("abacada") != isNaN("abacada") //false != true I need to abstract string and number and check, is some var really contains NaN (I mean NaN constant, but not-a-number value like strings). someobj.someopt = "blah"/0; someobj.someopt2 = "blah"; someobj.someopt3 = 150; for(a in someobj) if(Number.isNaN(someobj[a])) alert('!'); That

How to count nan values in a pandas DataFrame?

谁都会走 提交于 2019-12-06 17:12:16
问题 What is the best way to account for (not a number) nan values in a pandas DataFrame? The following code: import numpy as np import pandas as pd dfd = pd.DataFrame([1, np.nan, 3, 3, 3, np.nan], columns=['a']) dfv = dfd.a.value_counts().sort_index() print("nan: %d" % dfv[np.nan].sum()) print("1: %d" % dfv[1].sum()) print("3: %d" % dfv[3].sum()) print("total: %d" % dfv[:].sum()) Outputs: nan: 0 1: 1 3: 3 total: 4 While the desired output is: nan: 2 1: 1 3: 3 total: 6 I am using pandas 0.17 with

When I insert pandas Series into dataframe, all values become NaN

女生的网名这么多〃 提交于 2019-12-06 15:55:08
问题 I have a pandas series that looks like this: >>> myseries 2012-01-01 15:20:00-05:00 2 2012-01-01 15:30:00-05:00 1 2012-01-01 15:40:00-05:00 0 ... And I try to put it into a dataframe as so: >>> mydf = pd.DataFrame(myseries, columns=["myseries"], index = myseries.index) and all the values become NaN for some reason: >>> mydf 2012-01-01 15:20:00-05:00 NaN 2012-01-01 15:30:00-05:00 NaN 2012-01-01 15:40:00-05:00 NaN I'm pretty confused. This seems like a really simple application. What am I doing