nan

How to fix “NaN or infinity” issue for sparse matrix in python?

99封情书 提交于 2019-12-05 22:55:20
I'm totally new to python. I've used some code found online and I tried to work on it. So I'm creating a text-document-matrix and I want to add some extra features before training a logistic regression model. Although I've checked my data with R and I get no error, when I run the logistic regression I get the error "ValueError: Array contains NaN or infinity." I'm not getting the same error when I do not add my own features. My features are in the file "toPython.txt". Mind the two calls to assert_all_finite function that returns "None"! Below is the code I use and the output I get: def _assert

Cannot Fill NaN with zeros in a Pandas Dataframe

天涯浪子 提交于 2019-12-05 22:15:34
I have the following problem: I am reading a csv file with missing values by using pd.read_csv(f_name, sep=sep, header=hdr, parse_dates=True, index_col=date_col, quotechar=quote) The dataframe I get has 'nan's in it (I was expecting 'NaN's with the Upper cases). Now if I try to replace those nan's with zerosby using df.fillna(0) my df doesn't change (I still see nan's in it) My guess is that fillna is not working because I have nan (lowercase) instead of NaN (uppercase). Am I correct? If yes, do you have an idea why pd.read.csv returns a dataframe with lowercase nan's? I am using Python 2.7.6

Can std::numeric_limits::quiet_NaN double/float store some extra info

核能气质少年 提交于 2019-12-05 21:46:42
When storing double data in my data acquisition project, I identify all "missing" data using std::numeric_limits::quiet_NaN() . However, I'd like to store some extra information to know why the data is "missing" (data transmission lost, bad checksum, no measurement done, internal error....) so I need many different "nan" values in the end. And they must all be identified as NaN by any legacy code ( x!=x ). I see in IEEE 754-1985 that NaN fraction could be "anything except all 0 bits (since all 0 bits represents infinity).". Can the fraction be used to safely store some extra info? If yes, how

Loss in Tensorflow suddenly turn into nan

匆匆过客 提交于 2019-12-05 20:27:01
When I using tensorflow, the loss suddenly turn into nan, just like: Epoch: 00001 || cost= 0.675003929 Epoch: 00002 || cost= 0.237375346 Epoch: 00003 || cost= 0.204962473 Epoch: 00004 || cost= 0.191322120 Epoch: 00005 || cost= 0.181427178 Epoch: 00006 || cost= 0.172107664 Epoch: 00007 || cost= 0.171604740 Epoch: 00008 || cost= 0.160334495 Epoch: 00009 || cost= 0.151639721 Epoch: 00010 || cost= 0.149983061 Epoch: 00011 || cost= 0.145890004 Epoch: 00012 || cost= 0.141182279 Epoch: 00013 || cost= 0.140914166 Epoch: 00014 || cost= 0.136189088 Epoch: 00015 || cost= 0.133215346 Epoch: 00016 || cost=

Pandas Lambda Function with Nan Support

有些话、适合烂在心里 提交于 2019-12-05 13:33:24
I am trying to write a lambda function in Pandas that checks to see if Col1 is a Nan and if so, uses another column's data. I have having trouble getting code (below) to compile/execute correctly. import pandas as pd import numpy as np df=pd.DataFrame({ 'Col1' : [1,2,3,np.NaN], 'Col2': [7, 8, 9, 10]}) df2=df.apply(lambda x: x['Col2'] if x['Col1'].isnull() else x['Col1'], axis=1) Does anyone have any good idea on how to write a solution like this with a lambda function or have I exceeded the abilities of lambda? If not, do you have another solution? Thanks. You need pandas.isnull for check if

Python NaN JSON encoder

感情迁移 提交于 2019-12-05 12:11:46
问题 The default behavior for the JSON encoder is to convert NaNs to 'NaN', e.g. json.dumps(np.NaN) results in 'NaN'. How can I change this 'NaN' value to 'null'? I have tried to subclass the JSONEncoder and implement the default() method as follows: from json import JSONEncoder, dumps import numpy as np class NanConverter(JSONEncoder): def default(self, obj): try: _ = iter(obj) except TypeError: if isinstance(obj, float) and np.isnan(obj): return "null" return JSONEncoder.default(self, obj) >>> d

Angular Date filter is not workig in firefox

旧时模样 提交于 2019-12-05 12:07:40
I am using date filter to format my date in my angular application. In Firefox, I'm getting the date value as undefined NaN, NaN NaN:NaN:NaN PM In Chrome its works perfectly as Jun 25, 2014 7:22:47 AM My code is as follows. var formatDate = new Date(info.list[i].date); var newDate=$filter('date')(formatDate, 'medium'); How do I get it to work in Firefox? I ran into this issue and found that the problem was Chrome/Opera and Firefox/Safari have different tolerances for creating a new Javascript Date object. This works in Chrome and Opera, but not Firefox and Safari: var myDate = new Date("2014

Positive vs negative nans

瘦欲@ 提交于 2019-12-05 11:52:17
I have some numerical code that was developed on AMD64 Linux (using LLVM 3.2). I have recently ported it to OSX 10.9 with XCode. It runs fine, but it fails a lot of the unit tests: it seems that some calculations which on Linux return NaN (or -NaN) now return, on OSX, -NaN (or NaN). Can I safely assume that positive and negative NaNs are equivalent and adjust my unit tests to accept either as a success, or is this a sign of something more serious going wrong? There is no notion of a "negative NaN" in IEEE-754 arithmetic. The NaN encoding still has a sign bit, and there is a notion of a "sign

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

放肆的年华 提交于 2019-12-05 07:58:02
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 num3 = GetRandom<float>(); //... Is it possible that I will ever get back a NaN , Inf , or -Inf ? Let's

Comparing pandas Series for equality when they contain nan?

北城以北 提交于 2019-12-05 05:19:01
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? 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() == s2.isnull() Out[12]: 0 True 1 True dtype: bool Then check the values which aren't NaN are equal (using