nan

Rowwise min() and max() fails for column with NaNs

余生颓废 提交于 2019-12-23 09:38:23
问题 I am trying to take the rowwise max (and min) of two columns containing dates from datetime import date import pandas as pd import numpy as np df = pd.DataFrame({'date_a' : [date(2015, 1, 1), date(2012, 6, 1), date(2013, 1, 1), date(2016, 6, 1)], 'date_b' : [date(2012, 7, 1), date(2013, 1, 1), date(2014, 3, 1), date(2013, 4, 1)]}) df[['date_a', 'date_b']].max(axis=1) Out[46]: 0 2015-01-01 1 2013-01-01 2 2014-03-01 3 2016-06-01 as expected. However, if the dataframe contains a single NaN value

Error while creating heatmaps - NA/NaN/Inf in foreign function call (arg 11)

本小妞迷上赌 提交于 2019-12-23 09:03:09
问题 I'm trying to prepare heatmap for my data but I have no idea why this error appears. My data: > dput(head(tbl_ready)) structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.370330677123077, 0, 0, 0, 0, 0, 0.53318856142826, 0, 0, 0, 0, 0, 0.217669675587482, 0, 0, 0, 0.79337589572453, 0, 1, 0.0132525790616207, 0, 0, 1, 0.498415470211292, 0.216961707575178, 0.0646831352678839, 0, 0, 0, 0.778625047514492, 0.165974546372072, 0.076951015613392, 0.889894091237216, 0, 0, 1, 0.129806153151281, 0

What's wrong with std::nan/std::nanf under Visual Studio?

前提是你 提交于 2019-12-23 04:27:09
问题 Wanted to play with std::nan and std::nanf to create nan values with some custom payload (non boxing). However, it really does not work as expected: However, with Visual Studio 2015, the function apparently is not implemented right. The exact sample proposed by cppreference.com produces: nan("1") = nan (7ff8000000000000) nan("2") = nan (7ff8000000000000) Which is not what we expect. Is VS implementation wrong? If not, what would be the right arguments to use to produce 7ff8000000000001 and

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

ⅰ亾dé卋堺 提交于 2019-12-23 02:39:20
问题 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

Set all NaN elements in sparse matrix to zero

血红的双手。 提交于 2019-12-23 02:14:20
问题 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.) 回答1: 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

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

对着背影说爱祢 提交于 2019-12-22 10:38:58
问题 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

Javascript date returning NAN in IE8

佐手、 提交于 2019-12-22 10:27:10
问题 I am trying to parse date like this 2012-12-07T16:18:15+05:30 which I am receiving from database in string format. The parse function I am using is: var jstime = new Date("2012-12-07T16:18:15+05:30"); var h = jstime.getHours(); var m = jstime.getMinutes(); var s = jstime.getSeconds(); var f = "am" if(h >= 12) { f = "pm"; h = h - 12; } if(h == 0) { h = 12; } var str; str = jstime.toDateString(); str = str +"," + h.toString() + ":" + m.toString() + ":" + s.toString() + " " + f.toString();

Loss in Tensorflow suddenly turn into nan

﹥>﹥吖頭↗ 提交于 2019-12-22 09:54:43
问题 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

Check for None in pandas dataframe

五迷三道 提交于 2019-12-22 08:18:20
问题 I would like to find where None is found in the dataframe. pd.DataFrame([None,np.nan]).isnull() OUT: 0 0 True 1 True isnull() finds both numpy Nan and None values. I only want the None values and not numpy Nan. Is there an easier way to do that without looping through the dataframe? Edit: After reading the comments, I realized that in my dataframe in my work also include strings, so the None were not coerced to numpy Nan. So the answer given by Pisdom works. 回答1: You could use applymap with a

Positive vs negative nans

心已入冬 提交于 2019-12-22 08:16:05
问题 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? 回答1: There is no notion of a