In numpy land you often get nans for illegal mathematical operations. Consider >>> from math import asin >>> asin(1.1) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: math domain error Similar operation in numpy yields a nan: >>> from numpy import arcsin >>> arcsin(1.1) __main__:1: RuntimeWarning:...

This is very close to what you had, but replaces mean(x, na.rm=TRUE) with a custom function which either computes the mean of the non-NA values, or supplies NA itself: R> with(tab, aggregate(b, by=list(a), FUN=function(x) if (any(is.finite(z<-na.omit(x)))) mean(z) else NA)) Group.1 x 1 1 2 2 2 2 3 3 NA...

For some reason you have 2 sets of variables with the same names. You have static variables inputA, inputB, inputC that are never assigned (so have the default value 0.0). You also have instance variables inputA, inputB, inputC. These are assigned, using the values you enter. Unfortunately whatever values you...

For your first issue, I'd change the expression from a Sum to a Count (since it sounds like you're truly counting the matching records): =COUNT(IIF(Fields!CallbackStatus.Value="Completed",1,Nothing)) Regarding the NaN problem, it's returning NaN ("Not a Number"), because the expression is trying to divide by 0. I'd use an IIf expression such...

Not sure how it worked out, but changing the integration order from integral3(@(x,y,z) F(x,y,z),x1,x2,y1,y2,z1,z2) to integral3(@(z,x,y) F(x,y,z),z1,z2,x1,x2,y1,y2) solved the problem.

The skipna arg is a boolean specifying whether or not to exclude NA/null values, not which values to ignore: skipna : boolean, default True Exclude NA/null values. If an entire row/column is NA, the result will be NA Assuming I understand what you're trying to do, you could replace -9999...

java,user-interface,charts,javafx,nan

Probably best if you just make a divisor and call your axis billions or something. Otherwise you could set the range yourself and provide a formatter. Here's a snip from NumberAxis.java /** We use these for auto ranging to pick a user friendly tick unit. We handle tick units in...

Try isnan(). That's the one you're looking for. #include <math.h> void YourCode() { float x = /* some value from your array here */; if (isnan(x)) { // ... do stuff ... } } ...

Double.isNan does the job: scala> val array = Array(4,5,Double.NaN,6,5,6, Double.NaN) array: Array[Double] = Array(4.0, 5.0, NaN, 6.0, 5.0, 6.0, NaN) scala> array.count(_.isNaN) res0: Int = 2 ...

In short, both DataFrames and Series create an empty NumPy array and fill it with np.nan values, but DataFrame uses the passed str dtype for this array while Series overrides it with the 'O' (object) dtype. When no values are passed in, the __init__ method of both classes assigns an...

You need apply(your_func, axis=1) to work on a row-by-row basis. df Out[19]: PID CID PPID PPPID PPPPID PPPPPID 0 2015-01-02 456 2014-01-02 2014-01-02 2014-01-02 2014-01-02 1 2015-02-02 500 2014-02-02 2013-02-02 2012-02-02 2012-02-10 2 2010-12-04 300 2010-12-04 2010-12-04 2010-12-04 2010-12-04 df['counts'] = df.drop('CID', axis=1).apply(lambda row: len(pd.unique(row)), axis=1) Out[20]: PID CID PPID...

Depending on the type of your array, use Double.isNaN() or Float.isNaN().

Check for uninitialized variables. Quite often, if your program works as per expectations and then fails the next time you try running it again for the same workflow, the cause is uninitialized variables. Of course, there are many other things that can cause this, but uninitialized variables are a very...

There are two main issues: indexOf isn't the right method to use. Following the code step-by-step... arr[arr.indexOf(arr.length)] + arr[arr.indexOf(arr.length - 1)] arr[arr.indexOf(3)] + arr[arr.indexOf(2)] arr[2] + arr[1] 3 + 2 5 arr[arr.indexOf(arr.length)] + arr[arr.indexOf(arr.length - 1)]; arr[arr.indexOf(4)] + arr[arr.indexOf(3)] arr[-1] + arr[2] undefined + 2 NaN Setting result to 0...

Well, I would distinguish between the cases of NA/NaN/Infinity and the rest. I would certainly not convert them to zero as this would distort the result significantly while at the same time, not having any real mathematical sense. If a value is NA, then it is not, as the name...

c#,matlab,octave,nan,ilnumerics

Just use x[isnan(x)] = 0; This is directly equivalent to Matlabs syntax. Your first attempt suggests that you want to seperate non-NaN values from NaNs? If so, please clarify. ...

You have grammatical mistake in word length, it shouldn't be lenth but length in both cases. return v.values - remove values If all you want is to sort then you can use only sort function of javascript var s = list.sort(); All code complete: function getMiddle(list) { var s...

java,math,nan,arithmetic-expressions

You are getting the unexpected ArithmeticException because of the way that your numeric literals 3 and 0 are treated. They are interpreted as integers, despite the fact that you assign a to be a float. Java will interpret 3 as an integer, 3f as a float and 3.0 or 3d...

google-apps-script,nan,google-spreadsheet-api,google-form,google-apps-for-education

Your error may have to do with the preceding "+" sign in the email body string and the GAS compiler interpreting the string as a number. Try this code instead: function formSubmitReply(e){ var timeStamp = e.values[0]; var sendTo = e.values[1]; var ticket = e.values[2]; var description = e.values[3]; MailApp.sendEmail( sendTo,...

isNaN coerces its value to a number. (See MDN) Because the string representation of an array is all of its items concatenated with a comma. And the numerical representation of that is NaN because of the comma. But if there's only one item, hence no comma, it's able to be...

javascript,string,immutability,nan

Here is a simple example: var baz = "string"; baz = 5; Certainly we have not modified the value of the string "string" by assigning baz to 5. Instead, we have simply done away with the string altogether and put the value 5 in its place. Similarly, your example does...

As per ?zoo: Subscripting by a zoo object whose data contains logical values is undefined. So you need to wrap the subsetting in a which call: log_ret[which(!is.finite(log_ret))] <- 0 log_ret x y z s p t 2005-01-01 0.234 -0.012 0 0 0.454 0 ...

Youre trying to loop through $('#enttotalday'+ien) but there is only one value there so its casuing the issue. working code: setInterval( function(){ var b = $('input#ien_val').val(); var ien; for (ien = 1; ien < b; ien++) { // add parseInt var encuser = parseInt($('#enutt'+ien).val()); // add parseInt var enteam =...

python,list,nan,idl-programming-language

I dont know if python has NaN, just assume that is None. ta, tb = [], [] for i in range(min(len(a), len(b))): if a[i] is None or b[i] is None: continue ta.append(a[i]) tb.append(b[i]) ta, tb is your output of a,b at last you should append the rest item of the...

Tl;Dr : tagp argument gives you the ability to have different NAN values. This is from man page for nan(3) which gives a little more information on tagp. Mainly: The nan() functions return a quiet NaN, whose trailing fraction field contains the result of converting tagp to an unsigned integer....

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 =...

javascript,function,object,nan

You have to call the function as graphData.numData() and not graphData.numData since it's not a property and that will fix the problem. var graphData = { labels : ["label1", "label2", "label3"], numData : function(){return +(this.labels.length);} } var barWidth = 13; var viewWidth = barWidth * graphData.numData(); ...

It's not that all the values become nan, it's that (1) you're only looking at the parts that do, and (2) min and max don't work well with nans. For example, if we make an array resembling yours: >>> myarray = np.zeros((64, 52)) >>> myarray[3:-3,3:-3] = np.random.uniform(0, 5000, (64-6,52-6)) >>>...

javascript,canvas,nan,parseint

There are two errors here: 1) zombie1 does not have a property width, only w. Converting a non-number value using parseInt() will produce NaN. 2) You are adding the number (or rather NaN) to an object debugPlayer. This would have produced NaN in any case. To fix, try adding w...

I assume you have some sort of textbook or spec on whatever floating point spec you intend to simulate. Look in there for definitions. For something more general, you can read: http://en.wikipedia.org/wiki/NaN Here is what wikipedia says on sNaNs: Signaling NaN[edit] Signaling NaNs, or sNaNs, are special forms of a...

javascript,function,module,nan

price = transit.monthly / 2; Here you are telling the interpreter to use property monthly of object transit. In your code transit is a string so transit.monthly evaluates to undefined undefined / 2 evaluates to NaN I think you mean to pass in the variable objects you created instead of...

Currently there is no NA value available in Pandas or NumPy. From the section "Working with missing data" in the Pandas manual (http://pandas.pydata.org/pandas-docs/stable/missing_data.html): The choice of using NaN internally to denote missing data was largely for simplicity and performance reasons. It differs from the MaskedArray approach of, for example, scikits.timeseries....

How about this: cellfun(@(x) nansum(x,ndims(x)+1), raw_data, 'UniformOutput', false) Note if you're certain you'll only have 2D matrices in raw_data you can replace the ndims(x)+1 with 3. The idea is to use nansum to sum along the 3rd dimension as this will preserve the shape of the first 2 dimensions and...

Try this: import pandas as pd from numpy import * from pandas import * >>> L = [4, nan ,6] >>> df = Series(L) >>> df 0 4 1 NaN 2 6 >>> if(pd.isnull(df[1])): print "Found" Found >>> if(np.isnan(df[1])): print "Found" Found ...

python,pandas,boolean,nan,nonetype

Use any and pass param axis=1 which tests row-wise this will produce a boolean array which when converted to int will convert all True values to 1 and False values to 0, this will be much faster than calling apply which is going to iterate row-wise and will be very...

The code works as it should, exept if I leave score variable 0, I get a NaN output. You shouldn't do (examples from the Node.JS REPL): > var score = 0; var guesses = 1; var percentageTemp =((parseInt(score)/parseInt(guesses))*100); var percentage= percentageTemp.toFixed(2); console.log(percentage) 0.00 If, on the other hand, you...

python-2.7,pandas,dataframes,nan

You need to assign the result of fillna: df_pubs = df_pubs.fillna(0) or pass param inplace=True: df_pubs.fillna(0, inplace=True) See the docs You could modify your code to this: df_pubs = df_pubs.pivot(index='Conference', columns='Year', values='totalPubs').fillna(0) which would work but it's debatable whether the fillna is readable here....

When hangul.charAt(…) is not contained in your syllable map, the property access will yield undefined. Adding two undefineds together will make a NaN. You can prevent that from showing up by using the empty string as a default value for the lookup: function hangul_to_roman(hangul) { return (syllable_1[hangul.charAt(0)] || "") +...

I solved it using the solution provided by Matt at Matlab Central and modified it for case of rows instead of columns: function A = fill_nans(A) % Replaces the NaN in each column with % previous non-NaN values. for i = 1:size(A,1) I = A(1,i); for j = 2:size(A,2) if...

You've written: var g = parseInt("40000000") + "<br />"; Therefore g is a string: '40000000<br />'. parseInt("40000000") returns an integer, but then you append a string to it. Javascript implicitly converts the numer to a string, then concatenates them. String's not a number, so isNaN (correctly) returns true....

javascript,processing,nan,numeric,addition

JavaScript identifiers are case-sensitive, so nx and ny are not the same as nX and nY: nx = x; ny = y; ... x+=((nX-x)/delay); y+=((nY-y)/delay); ...

You can see that close has a space before it in the Index: Index([' close', 'eqId', 'date', 'IntDate', 'expiry', 'delta', 'ivMid', Hence the KeyError when trying to access the 'close' column. You have to access it via df[' close']. An alternative would be to apply strip to the columns to...

This behavior is by design. Note the comment in the documentation for the IValue.SetArray(...) method: If any of the numbers in the array are not valid numbers, the result of the custom function will be ValueError.Num. Since NaN isn't a valid number the entire array will resolve to #NUM! instead....

You can use multiple boolean conditions to test if the current value and previous value are NaN: In [3]: df = pd.DataFrame({'a':[1,3,np.NaN, np.NaN, 4, np.NaN, 6,7,8]}) df Out[3]: a 0 1 1 3 2 NaN 3 NaN 4 4 5 NaN 6 6 7 7 8 8 In [6]: df[(df.a.isnull())...

sql,sql-server,vb.net,floating-point,nan

First, Never concatenate strings to create sql statements. This is a security risk as it's an open door for Sql injection attacks. Use parameterized queries instead. Second, I would recommend using null to represent NaN values since 0.0 is a valid float value and NaN stands for Not A Number,...

Whenever you divide the number by 0 it becomes Infinity not false.

jquery,jquery-ui,datepicker,nan,calculated

Do the total calculation only if both the values are present function total() { //looks like getDate is returning an array var start = $('#from').datepick('getDate')[0]; var end = $('#to').datepick('getDate')[0]; var total = start && end ? (end.getTime() - start.getTime()) / 1000 / 60 / 60 / 24 : ''; $('#total_days').val(total);...

A slight error in how you are accessing the arrays. you'll need parseInt(beaconCoordinates[0][0]); rather then parseInt(beaconCoordinates[0,0]);...

Logical indexing with rowSums and colSums (in the right locations) gives a very compact and efficient answer: M[rowSums(is.na(M)) < 0.8*nrow(M), ][ , colSums(is.na(M))< 0.8*ncol(M)] [,1] [,2] [,3] [,4] [,5] [1,] 0.00000e+00 3.75882e-06 3.71645e-05 2.16088e-06 1.35700e-06 [2,] 3.75882e-06 0.00000e+00 3.94165e-05 3.58464e-06 3.60392e-06 [3,] 3.71645e-05 3.94165e-05 0.00000e+00 3.78173e-05 3.70121e-05 [4,] 2.16088e-06 3.58464e-06...

It was NaN because you did not initialize result at the start. Let us see the script: var result = 0; var x; for (var i = 0; i<100; i++) { x = i ^ i result = x + result; } Here you are running the bitwise XOR for...

python,arrays,numpy,pandas,nan

Using pandas would make your life quite easier (note the regular expression to define delimiter): from pandas import read_csv data = read_csv('data.dat', delimiter='\s+').values print(data[~np.isnan(data[:, 2])][:, [0, 2]]) Which results in: array([[ 8.00000000e+00, 5.12000000e+02], [ 9.00000000e+00, 7.29000000e+02], [ 1.00000000e+01, 1.00000000e+03], [ 1.20000000e+01, 1.72800000e+03], [ 1.60000000e+01, 4.09600000e+03], [ 1.90000000e+01, 6.85900000e+03], [ 2.10000000e+01,...

Vectorized approach to set appropriate elements as NaNs @unutbu's solution must get rid of the value error you were getting. If you are looking to vectorize for performance, you can use boolean indexing like so - import numpy as np # Create mask of positions in x (with float datatype)...

javascript,jquery,forms,function,nan

None of your selectors like $('#totalitF'+number) will work, because you're not appending numbers to your IDs. Instead of: id="totalitF" no="'+ lineNum +'"/>' it should be: id="totalitF'+ lineNum +'" data-no="'+ lineNum +'"/>' You shouldn't create your own attributes. If you want to add additional attributes to an element, use data- attributes....

By default, fillna will return the filled DataFrame and not work on it "in-place", as such you have to do: MyData.level = MyData.level.fillna(0) Alternatively you can pass inplace=True when calling it, and it will work in-place, so: MyData.level.fillna(0, inplace=True) ...

pandas,count,row,dataframes,nan

You could first find if element is NaN or not by isnull() and then take row-wise sum(axis=1) In [195]: df.isnull().sum(axis=1) Out[195]: 0 0 1 0 2 0 3 3 4 0 5 0 dtype: int64 And, if you want the output as list, you can In [196]: df.isnull().sum(axis=1).tolist() Out[196]: [0,...

java,random,distribution,nan,gaussian

In your code dRandom1 can be negative, while real logarithms only take arguments from (0, +inf)

The error message you get is quite informative: it seems you do not have enough observations to compute t.test. Your question is however on how to produce NA's instead of errors that break the loops. In this case you can use tryCatch or try (simplified version of tryCatch): tryCatch(t.test(x ~...

ios,swift,floating-point,operators,nan

You are actually doing let x = 0 / 0 = nan = (not a number) So you need to make sure your code don't do that calculation until the user inputs his/her weight and calories amount or just set a minimum value for yourWeight and calorieNumber vars other than...

I fixed this. it turns out I had the same class (btn-primary) on the submit button which was throwing it all out. Once I changed the class on the actual select buttons so it didn't clash with the submit, it worked....

If A is a 2D array, e.g. A = [1, 2, 3, 4, 5, NaN, NaN, NaN, NaN, NaN; 1, 2, 3, 4, 5, 6, 7, NaN, NaN, NaN; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and you want to count the number of NaN entries on...

javascript,jquery,variables,var,nan

You have a scope problem, this is what is going on: You declare cur_lv as 1 [line 2] (because it's not inside a function, cur_lv will be a global variable). Inside the click function for #btn_up and #btn_down you are declaring a new variable with local scope (the var statement...

arrays,matlab,matrix,replace,nan

isnan(data2winner(3,:)) gives you a logical array of ones and zeros where NaNs are present or not respectively in the third row. Then, you were needed to index into the third row of the input matrix and select the columns that had NaNs (ones from isnan output) and set them to...

The technique I ended up using was the function nanconv.m at Matlab's File Exchange. It does exactly what I was looking for: it runs the filter in a way that ignores the NaNs just the way that Matlab's built-in function nanmean does. This is a hard to decipher from the...

Consider the following: n = 0; Object.defineProperty(window, 'a', { get: function() { return n++; } }); > a === a < false ...

localization,transform,nan,ros

If anyone has the same issue, a full IMU mock message is like the following: #!/usr/bin/env python import sys import roslib import rospy import math import numpy as np from geometry_msgs.msg import Twist, Point from sensor_msgs.msg import Imu from std_msgs.msg import Int64 from tf.transformations import quaternion_about_axis def imu_publisher(): vel_x =...

NMaybe you can put them in an array and get the Sum() : double SumLiqPerTimeStamp = new double[]{ l2_msg.size0 , l2_msg.size1 , l2_msg.size2 , l2_msg.size3 ,l2_msg.size4 , l2_msg.size5 , l2_msg.size6 , l2_msg.size7 , l2_msg.size8 , l2_msg.size9 }.Where( x => !double.IsNaN(x) ).Sum(); ...

python,numpy,nan,ieee-754,multidimensional-array

On newer versions of numpy you get this warning: FutureWarning: numpy equal will not check object identity in the future. The comparison did not return the same result as suggested by the identity (`is`)) and will change. my guess is that numpy is using id test as a shortcut, for...

You can do it easily with a loop or use arrayfun like this: A = [NaN, 2, 3, 4, NaN, NaN, NaN, 13, 45, 35, NaN, 6, NaN] i1 = find(diff(isnan(A))==-1)+1 %// Index where clusters of numbers begin i2 = find(diff(isnan(A))==1) %// Index where clusters of numbers end data_cell_filt =...

It is because of the logic you have used to find the sibling price/area element. Assume you have added 4 items, so you have elements like area0/area1/area2/area3. Now you are deleting row 2 so the element area1 is no longer present then in your each loop in the second iteration...

From the documentaton: The Oracle Database numeric data types store positive and negative fixed and floating-point numbers, zero, infinity, and values that are the undefined result of an operation—"not a number" or NAN. As far as I'm aware you can only get NaN in a binary_float or binary_double column; those...

Read the json file into a variable: x = '''[{"city": "Los Angeles","job":"chef","age":30}, {"city": "New York","job":"driver","age":35}, {"city": "San Jose","job":"pilot","age":NaN}]''' Now, load it with json.loads In [41]: import json In [42]: y = json.loads(x) In [43]: y Out[43]: [{u'age': 30, u'city': u'Los Angeles', u'job': u'chef'}, {u'age': 35, u'city': u'New York', u'job': u'driver'},...

python,arrays,numpy,matrix,nan

You are getting rid of items which are NaN, not of rows with NaN. The proper thing to do would be: mask = ~np.any(np.isnan(x), axis=1) x = x[mask] y = y[mask] To see the different behavior of both approaches: >>> x = np.random.rand(4, 5) >>> x[[0, 2], [1, 4]] =...

python,pandas,dataframes,user-defined-functions,nan

I think your code is pretty solid, the main issue is you are iterating through it more times than you need to. shift() only goes back one line at a time, but if you change that to fillna(method='ffill') then you essentially get an unlimitied number of shifts but only have...

np.nan has type float: arrays containing it must also have this datatype (or the object datatype) so you may need to recast arr before you try to assign the value. The error arises because the string value 'nan' can't be converted to an integer type to match arr's type. The...

If you would like null-values instead of 'NaN' you could simply use: SELECT name, NULLIF(age, 'NaN') From "People" ...

It seems like Eigen doesn't implement any of this functionality itself. In general, it looks like the best you can do is to replace NaN values with something else via select: for example, the following replaces elements of x less than 3 with 0 x = (x.array() < 3).select(0, x);...

javascript,nan,compound-assignment

You can't add a number to undefined in JavaScript. If you don't want to initialize the number, you need to test if it's undefined before incrementing it: test['value'] = (typeof test['value']==='undefined') ? 10 : test['value']+10; ...

You need to initialize the arrays to contain 0: var oldTherms = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; var newTherms = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; Otherwise, you're adding newInputTherms and oldInputTherms to undefined, and the result...

javascript,internet-explorer-8,nan

It's hard to test your code, since you did not say which variable goes to the "output" (the output would be the location in your code that displays NaN) But did a test with the variables and realized that the problem is with your XMLHttpRequest. XMLHttpRequest with 'POST' return headers...

The difference resides in the data held by the two structures. Using a regular array with np.nan, there is no data behind invalid values. Using a masked array, you can initialize a full array, and then apply a mask over it so that certain values appear invalid. The numpy.ma module...

python,numpy,pandas,nan,data-cleaning

If there aren't 0's that mean anything, it's fine to fill the NA's with a value (0 for convenience). It all depends on your data. That said, 300 x 30k isn't that big. Save it off as a CSV and just experiment in IPython Notebook, Pandas can probably read it...

0x7fa00000 is a signalling NaN ("sNaN"). 0x7fe00000 is a quiet NaN ("qNaN"). I haven't heard of this behavior under x86, but under ARM sNaNs get converted to qNaNs when used in operations, alongside raising an FP exception (which is normally ignored). It looks like the same thing is happening here....

This one-liner seems to work as well: >>> df = pd.DataFrame(np.nan, index=[0,1,2,3], columns=['A']) >>> df.dtypes A float64 dtype: object ...

python,arrays,numpy,nan,genfromtxt

You can iterate over rows and create a mask for rows, then use boolean indexing to get the view of rows that passed: import numpy as np field = [1,2,3,3,2,1,-1,4,1,2] polarization = [-1, 10,230,13,123,50,102,90,45,1337] error = [0.1, 0.1, 0.2, 0.1, 0.1, 0.3, 0.1, 0.1, 0.4, 0.2] #transposition is needed to...

python,arrays,numpy,nan,median

import numpy as np from numpy import NaN x = np.array([NaN,NaN,0.1,0.002,0.14,NaN,NaN,NaN]) def getMedian(arr): med = np.median(arr) if np.isnan(med): return np.nanmax(arr) else: return med print getMedian(x) ...

c++,boost,nan,boost-accumulators

You could use the accumulator count: if (boost::accumulators::count(acc) == 0)//I don't know what function here return 0; else return boost::accumulators::mean(acc); Alternatively, you could simply check if it is nan by calling std::isnan: if(std::isnan(boost::accumulators::mean(acc)) return 0; else return boost::accumulators::mean(acc); ...

Values returned from prompt are always strings, so make sure to coerce them to numbers, and coerce undefined or null values as well number + undefined = NaN...

javascript,arrays,nested-loops,nan,factorial

Wrong (or at least: odd) things in your code: f is a number. You seem to expect your function to return an array, though? i <= params.length should be i < params.length. Array indices start at 0, and end at length-1. You are multiplying your accumulator variable with params[j] -...

This seems to achieve my objective: import simplejson >>> simplejson.dumps(d, ignore_nan=True) Out[3]: '{"a": 1, "c": 3, "b": 2, "e": null, "f": [1, null, 3]}' ...