nan

Why check for !isNaN() after isFinite()?

自古美人都是妖i 提交于 2019-12-20 09:39:51
问题 I came across the goog.math.isFiniteNumber function in the Google Closure Library. What it does is checking whether a given number is both finite and not NaN . The underlying code is: goog.math.isFiniteNumber = function(num) { return isFinite(num) && !isNaN(num); }; So, first it checks whether the number is finite using the native isFinite function, and then does an additional check to make sure the number isn't NaN using isNaN . However, isFinite already returns false in case the argument is

Fast check for NaN in NumPy

天大地大妈咪最大 提交于 2019-12-20 08:16:16
问题 I'm looking for the fastest way to check for the occurrence of NaN ( np.nan ) in a NumPy array X . np.isnan(X) is out of the question, since it builds a boolean array of shape X.shape , which is potentially gigantic. I tried np.nan in X , but that seems not to work because np.nan != np.nan . Is there a fast and memory-efficient way to do this at all? (To those who would ask "how gigantic": I can't tell. This is input validation for library code.) 回答1: Ray's solution is good. However, on my

weird NaN when raising a number to a non-integer power [duplicate]

↘锁芯ラ 提交于 2019-12-20 06:13:10
问题 This question already has answers here : Exponentiation with negative base (2 answers) Closed 4 years ago . I executed the following code: tau <- 0.25 h <- 0.6 * n ^ (-1 / 5) * (4.5 * dnorm(qnorm(tau)) ^ 4 * qnorm(tau) / (2 * (qnorm(tau) ^ 2 + 1)) ^ 2) ^ (1/5), and R keeps producing NaN . However, R actually computes (4.5 * dnorm(qnorm(tau)) ^ 4 * qnorm(tau) / (2 * (qnorm(tau) ^ 2 + 1)) ^ 2) to be equal to -0.003655336 . The weird thing is when I did the following k <- -0.003655336 k ^ (1 / 3

Remove a tuple containing nan in list of tuples — Python

▼魔方 西西 提交于 2019-12-20 05:13:31
问题 I have a long list of tuples and want to remove any tuple that has a nan in it using Python. What I currently have: x = [('Recording start', 0), (nan, 4), (nan, 7), ..., ('Event marker 1', 150)] Result I'm looking for: x = [('Recording start', 0), ('Event marker 1', 150)] I've tried use np.isnan and variants of that, but have had no success and keep getting an error: ufunc 'isnan' is not supported for the input types, and the inputs could not be safely coerced to any supported types according

Remove a tuple containing nan in list of tuples — Python

心已入冬 提交于 2019-12-20 05:13:04
问题 I have a long list of tuples and want to remove any tuple that has a nan in it using Python. What I currently have: x = [('Recording start', 0), (nan, 4), (nan, 7), ..., ('Event marker 1', 150)] Result I'm looking for: x = [('Recording start', 0), ('Event marker 1', 150)] I've tried use np.isnan and variants of that, but have had no success and keep getting an error: ufunc 'isnan' is not supported for the input types, and the inputs could not be safely coerced to any supported types according

Is there any general way to remove NaNs from a matrix?

故事扮演 提交于 2019-12-20 02:22:32
问题 Is there any general way to remove NaNs from a matrix? Sometimes I come across this problem in the middle of some code and then it creates problems to get appropriate outputs. Is there any way to generate any kind of check to avoid NaNs arising in a MATLAB code? It will be really helpful if someone can kindly give me an example with some idea related to it. 回答1: You can detect nan values with the isnan function: A = [1 NaN 3]; A(~isnan(A)) 1 3 This actually removes nan values, however this is

hatch a NaN region in a contourplot in matplotlib

我们两清 提交于 2019-12-20 02:17:51
问题 I am contourplotting a matrix of data. Some of the matrix's elements are NaN's (corresponding to parameter combinations where no solution exists). I would like to indicate this region in the contourplot by a hatched region. Any idea on how to achieve this? 回答1: contourf and contour methods don't draw anything where an array is masked (see here)! So, if you want the NaN elements region of the plot to be hatched, you just have to define the background of the plot as hatched. See this example:

df.fillna(0) command won't replace NaN values with 0

风格不统一 提交于 2019-12-19 09:26:40
问题 I'm trying to replace the NaN values generated in the code below to 0. I don't understand what the below won't work. It still keeps the NaN values. df_pubs=pd.read_sql("select Conference, Year, count(*) as totalPubs from publications where year>=1991 group by conference, year", db) df_pubs['Conference'] = df_pubs['Conference'].str.encode('utf-8') df_pubs = df_pubs.pivot(index='Conference', columns='Year', values='totalPubs') df_pubs.fillna(0) print df_pubs print df produces this: Year 1991 \

Can I temporarily enable FTZ and DAZ floating-point modes for a thread?

孤街醉人 提交于 2019-12-19 09:21:37
问题 I'd like to enable temporarily FTZ / DAZ modes to get a performance gain for some code where strict compliance with the IEEE 754 standard is not an issue, without changing the behaviour of other threads, which could be executing code, where that compliance is important. I've been reading this on how to enable/disable these modes and this on the performance impact of denormals handling, but unfortunately I've got a mixed code in a multithreaded environment and I cannot enable these modes once

Nullable double NaN comparison in C#

无人久伴 提交于 2019-12-19 07:55:15
问题 I have 2 nullable doubles, an expected value and an actual value (let's call them value and valueExpected). A percentage is found using 100 * (value / valueExpected). However, if valueExpected is zero, it returns NaN. Everything good so far. Now, what do I do if I need to check the value, to see if it is NaN? Normally one could use: if (!Double.IsNaN(myDouble)) But this doesn't work with nullable values (IsNaN only works with non-nullable variables). I have changed my code to do the check