Search Results

Search found 175 results on 7 pages for 'nan'.

Page 1/7 | 1 2 3 4 5 6 7  | Next Page >

  • Sorting an array of Doubles with NaN in it

    - by Agent Worm
    This is more of a 'Can you explain this' type of question than it is anything else. I came across a problem at work where we were using NaN values in a table, but when the table was sorted, it came out in a very strange, strange manner. I figured NaN was mucking up something so I wrote up a test application to see if this is true. This is what I did. static void Main(string[] args) { double[] someArray = { 4.0, 2.0, double.NaN, 1.0, 5.0, 3.0, double.NaN, 10.0, 9.0, 8.0 }; foreach (double db in someArray) { Console.WriteLine(db); } Array.Sort(someArray); Console.WriteLine("\n\n"); foreach (double db in someArray) { Console.WriteLine(db); } Console.ReadLine(); } Which gave the result: Before: 4,2,NaN,1,5,3,NaN,10,9,8 After: 1,4,NaN,2,3,5,8,9,10,NaN So yes, the NaN some how made the sorted array to be sorted in a strange way. To quote Fry; "Why is those things?"

    Read the article

  • Javas Math.sin() produces NaN all the time

    - by milan1612
    Forgive me if this is a dumb beginners problem, but I really don't get it. I have a member variable declared like so: public Double Value; When I assign 3.14159265 to Value and try to compute the sine of it, this happens: system.out.println(Value.toString()); //outputs 3.14159265 Value = Math.sin(Value); system.out.println(Value.toString()); //outputs NaN In fact, this happens with every single value I tried - even with 0! Math.sin() seems to always produce NaN as a result, regardless of the arguments value. The docs say: If the argument is NaN or an infinity, then the result is NaN. But my argument is clearly not NaN or infinity! What the heck is happening there?

    Read the article

  • Is there a better way of making numpy.argmin() ignore NaN values

    - by Dragan Chupacabrovic
    Hello Everybody, I want to get the index of the min value of a numpy array that contains NaNs and I want them ignored >>> a = array([ nan, 2.5, 3., nan, 4., 5.]) >>> a array([ NaN, 2.5, 3. , NaN, 4. , 5. ]) if I run argmin, it returns the index of the first NaN >>> a.argmin() 0 I substitute NaNs with Infs and then run argmin >>> a[isnan(a)] = Inf >>> a array([ Inf, 2.5, 3. , Inf, 4. , 5. ]) >>> a.argmin() 1 My dilemma is the following: I'd rather not change NaNs to Infs and then back after I'm done with argmin (since NaNs have a meaning later on in the code). Is there a better way to do this? There is also a question of what should the result be if all of the original values of a are NaN? In my implementation the answer is 0

    Read the article

  • double.NaN Equality in MS Test

    - by RichK
    Why am I getting this result? [TestMethod] public void nan_test() { Assert.AreEqual(1, double.NaN, 1E-1); <-- Passes Assert.AreEqual(1, double.NaN); <-- Fails } What difference does the delta have in asserting NaN equals a number? Surely it should always return false. I am aware of IsNaN, but that's not useful here (see below). Background: I have a function returning NaN (erroneously) , it was meant to be a real number but the test still passed. I'm using the delta because it's double precision equality, the original test used 1E-9.

    Read the article

  • Equality with Double.NaN

    - by chris
    I have the following code... if (Price_Foreign != Double.NaN) { output.Append(spacer); output.Append(String.Format("{0,-10:C} USD",Price_Foreign)); } Which outputs: NaN USD What gives? I'm using Double.NaN to indicate that the value doesn't exist, and shouldn't be output.

    Read the article

  • ActionScript black color value is NaN

    - by TheDarkIn1978
    i'm trying to determine if a color has been supplied as an optional argument to a function. in order to determine this, i'm simply writing if(color){...} and supplying NaN if i don't want there to be a color. however, it seems that the color black (0x000000) also equates to NaN. how can i determine if a supplied color number argument is present and black if 0x000000 is passed as the argument?

    Read the article

  • From NaN to Infinity...and Beyond!

    - by Tony Davis
    It is hard to believe that it was once possible to corrupt a SQL Server Database by storing perfectly normal data values into a table; but it is true. In SQL Server 2000 and before, one could inadvertently load invalid data values into certain data types via RPC calls or bulk insert methods rather than DML. In the particular case of the FLOAT data type, this meant that common 'special values' for this type, namely NaN (not-a-number) and +/- infinity, could be quite happily plugged into the database from an application and stored as 'out-of-range' values. This was like a time-bomb. When one then tried to query this data; the values were unsupported and so data pages containing them were flagged as being corrupt. Any query that needed to read a column containing the special value could fail or return unpredictable results. Microsoft even had to issue a hotfix to deal with failures in the automatic recovery process, caused by the presence of these NaN values, which rendered the whole database inaccessible! This problem is history for those of us on more current versions of SQL Server, but its ghost still haunts us. Recently, for example, a developer on Red Gate’s SQL Response team reported a strange problem when attempting to load historical monitoring data into a SQL Server 2005 database via the C# ADO.NET provider. The ratios used in some of their reporting calculations occasionally threw out NaN or infinity values, and the subsequent attempts to load these values resulted in a nasty error. It turns out to be a different manifestation of the same problem. SQL Server 2005 still does not fully support the IEEE 754 standard for floating point numbers, in that the FLOAT data type still cannot handle NaN or infinity values. Instead, they just added validation checks that prevent the 'invalid' values from being loaded in the first place. For people migrating from SQL Server 2000 databases that contained out-of-range FLOAT (or DATETIME etc.) data, to SQL Server 2005, Microsoft have added to the latter's version of the DBCC CHECKDB (or CHECKTABLE) command a DATA_PURITY clause. When enabled, this will seek out the corrupt data, but won’t fix it. You have to do this yourself in what can often be a slow, painful manual process. Our development team, after a quizzical shrug of the shoulders, simply decided to represent NaN and infinity values as NULL, and move on, accepting the minor inconvenience of not being able to tell them apart. However, what of scientific, engineering and other applications that really would like the luxury of being able to both store and access these perfectly-reasonable floating point data values? The sticking point seems to be the stipulation in the IEEE 754 standard that, when NaN is compared to any other value including itself, the answer is "unequal" (i.e. FALSE). This is clearly different from normal number comparisons and has repercussions for such things as indexing operations. Even so, this hardly applies to infinity values, which are single definite values. In fact, there is some encouraging talk in the Connect note on this issue that they might be supported 'in the SQL Server 2008 timeframe'. If didn't happen; SQL 2008 doesn't support NaN or infinity values, though one could be forgiven for thinking otherwise, based on the MSDN documentation for the FLOAT type, which states that "The behavior of float and real follows the IEEE 754 specification on approximate numeric data types". However, the truth is revealed in the XPath documentation, which states that "…float (53) is not exactly IEEE 754. For example, neither NaN (Not-a-Number) nor infinity is used…". Is it really so hard to fix this problem the right way, and properly support in SQL Server the IEEE 754 standard for the floating point data type, NaNs, infinities and all? Oracle seems to have managed it quite nicely with its BINARY_FLOAT and BINARY_DOUBLE types, so it is technically possible. We have an enterprise-class database that is marketed as being part of an 'integrated' Windows platform. Absurdly, we have .NET and XPath libraries that fully support the standard for floating point numbers, and we can't even properly store these values, let alone query them, in the SQL Server database! Cheers, Tony.

    Read the article

  • When can Java produce a NaN (with specific code question)

    - by Brent
    I'm a bit perplexed by some code I'm currently writing. I am trying to preform a specific gradient descent (main loop included below) and depending on the initial conditions I will alternatively get good looking results (perhaps 20% of the time) or everything becomes NaN (the other 80% of the time). However it seems to me that none of the operations in my code could produce NaN's when given honest numbers! My main loop is: // calculate errors delta = m1 + m2 - M; eta = f1 + f2 - F; for (int i = 0; i < numChildren; i++) { epsilon[i] = p[i]*m1+(1-p[i])*m2+q[i]*f1+(1-q[i])*f2-C[i]; } // use errors in gradient descent // set aside differences for the p's and q's float mDiff = m1 - m2; float fDiff = f1 - f2; // first update m's and f's m1 -= rate*delta; m2 -= rate*delta; f1 -= rate*eta; f2 -= rate*eta; for (int i = 0; i < numChildren; i++) { m1 -= rate*epsilon[i]*p[i]; m2 -= rate*epsilon[i]*(1-p[i]); f1 -= rate*epsilon[i]*q[i]; f2 -= rate*epsilon[i]*(1-q[i]); } // now update the p's and q's for (int i = 0; i < numChildren; i++) { p[i] -= rate*epsilon[i]*mDiff; q[i] -= rate*epsilon[i]*fDiff; } This behavior can be seen when we have rate = 0.01; M = 30; F = 30; C = {15, 25, 35, 45}; with the p[i] and q[i] chosen randomly uniformly between 0 and 1, m1 and m2 chosen randomly uniformly to add to M, and f1 and f2 chosen randomly uniformly to add up to F. Does anyone see anything that could create these NaN's?

    Read the article

  • NAN mixing float and GLFloat?

    - by carrots
    This often returns NAN ("Not A Number") depending on input: #define PI 3.1415f GLfloat sineEaseIn(GLfloat ratio) { return 1.0f-cosf(ratio * (PI / 2.0f)); } I tried making PI a few digits smaller to see if that would help. No dice. Then I thought it might be a datatype mismatch, but float and glfloat seem to be equivalent: gl.h typedef float GLfloat; math.h extern float cosf( float ); Is this a casting issue?

    Read the article

  • In Javascript, how to avoid NaN when adding arrays

    - by Jonas
    I'm trying to add the values of two arrays in javascript eg. [1,2,1] + [3,2,3,4] The answer should be 4,4,4,4 but I'm either getting 4,4,4 or 4,4,4,NaN if I change the 1st array length to 4. I know a 4th number needs to be in the 1st array, but i can't figure out how to tell javascript to make it 0 rather then undefined if there is no number.

    Read the article

  • Why does this code sometimes return NaN?

    - by carrots
    This often returns NAN ("Not A Number") depending on input: #define PI 3.1415f GLfloat sineEaseIn(GLfloat ratio) { return 1.0f-cosf(ratio * (PI / 2.0f)); } I tried making PI a few digits smaller to see if that would help. No dice. Then I thought it might be a datatype mismatch, but float and glfloat seem to be equivalent: gl.h typedef float GLfloat; math.h extern float cosf( float ); Is this a casting issue?

    Read the article

  • I get NaN when I try to insert some HTML into a DIV element with jQuery

    - by Ankur
    I am tring to display a text box when a element of class numObj is clicked. For some reason I get NaNNaNaNaNNaNNaNaNaN where I expect to the see the result of the searchForm variable in the code below. I know that NaN stands for Not a Number. What I don't understand is why is Javascript expecting a number? I can't understand why it cares. $(".numObj").live('click',function(){ var preId = $(this).attr('preId'); var arrayPos = $(this).attr('numArrayPos'); alert(preId +" "+arrayPos); var searchForm = "<table border='0' cellspacing='0' cellpadding='4' id='add-tag2'>"+ +"<tr class='normal'><td bgcolor='#EEEEEE' valign='bottom' nowrap='nowrap'><span class='normal-small'>"+ +"<input name='predicate-name2' type='text' class='normal' id='predicate-name2' size='4' />"+ +"</span></td>"+ +"<td bgcolor='#EEEEEE' valign='bottom' nowrap='nowrap'><span class='normal-small'>&lt;=</span></td>"+ +"<td bgcolor='#EEEEEE' valign='bottom' nowrap='nowrap'>x</td>"+ +"<td valign='bottom' bgcolor='#EEEEEE'>&lt;=</td>"+ +"<td valign='bottom' bgcolor='#EEEEEE'><span class='normal-small'>"+ +"<input type='text' name='object-object2' id='object-object2' class='normal' size='4' />"+ +"</span></td>"+ +"</tr>"+ +"</table>"; $(".numObj").filter("[preId='"+preId+"']").filter("[numArrayPos='"+arrayPos+"']").html(searchForm); }); The generated code that has the numObj class looks something like this <td><div class="numObj" preid="73" numarraypos="5"><span class="normal">585.0</span></div></td>

    Read the article

  • Cacti rrdtool graph with no values, NaN in .rrd file

    - by beicha
    Cacti 0.8.7h, with latest RRDTool. I successfully graphed CPU/Interface traffic, but got blank graphs like when it comes to Memory/Temperature monitoring. The problem/bug is actually archived here, however this post didn't help. I can snmpget the value, e.g SNMPv2-SMI::enterprises.9.9.13.1.3.1.3.1 = Gauge32: 26. However, the problem seems to exist in storing these values to the .rrd file. Output of rrdtool info powerbseipv6testrouter_cisco_memfree_40.rrd AVERAGE cisco_memfree as below: filename = "powerbseipv6testrouter_cisco_memfree_40.rrd" rrd_version = "0003" step = 300 last_update = 1321867894 ds[cisco_memfree].type = "GAUGE" ds[cisco_memfree].minimal_heartbeat = 600 ds[cisco_memfree].min = 0.0000000000e+00 ds[cisco_memfree].max = 1.0000000000e+12 ds[cisco_memfree].last_ds = "UNKN" ds[cisco_memfree].value = 0.0000000000e+00 ds[cisco_memfree].unknown_sec = 94 rra[0].cf = "AVERAGE" rra[0].rows = 600 rra[0].pdp_per_row = 1 rra[0].xff = 5.0000000000e-01 rra[0].cdp_prep[0].value = NaN rra[0].cdp_prep[0].unknown_datapoints = 0 rra[1].cf = "AVERAGE" rra[1].rows = 700 rra[1].pdp_per_row = 6 rra[1].xff = 5.0000000000e-01 rra[1].cdp_prep[0].value = NaN rra[1].cdp_prep[0].unknown_datapoints = 0 rra[2].cf = "AVERAGE" rra[2].rows = 775 rra[2].pdp_per_row = 24 rra[2].xff = 5.0000000000e-01 rra[2].cdp_prep[0].value = NaN rra[2].cdp_prep[0].unknown_datapoints = 18 rra[3].cf = "AVERAGE" rra[3].rows = 797 rra[3].pdp_per_row = 288 rra[3].xff = 5.0000000000e-01 rra[3].cdp_prep[0].value = NaN rra[3].cdp_prep[0].unknown_datapoints = 114 rra[4].cf = "MAX" rra[4].rows = 600 rra[4].pdp_per_row = 1 rra[4].xff = 5.0000000000e-01 rra[4].cdp_prep[0].value = NaN rra[4].cdp_prep[0].unknown_datapoints = 0 rra[5].cf = "MAX" rra[5].rows = 700 rra[5].pdp_per_row = 6 rra[5].xff = 5.0000000000e-01 rra[5].cdp_prep[0].value = NaN rra[5].cdp_prep[0].unknown_datapoints = 0 rra[6].cf = "MAX" rra[6].rows = 775 rra[6].pdp_per_row = 24 rra[6].xff = 5.0000000000e-01 rra[6].cdp_prep[0].value = NaN rra[6].cdp_prep[0].unknown_datapoints = 18 rra[7].cf = "MAX" rra[7].rows = 797 rra[7].pdp_per_row = 288 rra[7].xff = 5.0000000000e-01 rra[7].cdp_prep[0].value = NaN rra[7].cdp_prep[0].unknown_datapoints = 114

    Read the article

  • Why do MSTests Assert.AreEqual(1.0, double.NaN, 0.0) pass?

    - by Egil Hansen
    Short question, why do Assert.AreEqual(1.0, double.NaN, 0.0) pass when Assert.AreEqual(1.0, double.NaN) do not? Is it an error in MSTest or am I missing something here? Best regards, Egil. Update: Should probably add, that the reason behind my question is, that I have a bunch of unit tests that unfortunately passed due to the result of some linear algebraic matrix operation being NaN or (+/-)Infinity. The unit tests are fine, but since Assert.AreEqual on doubles with a delta will pass when actual or/and expected are NaN or Infinity, I was left to believe that the code I was testing was correct.

    Read the article

  • Why does typeof NaN return 'number'?

    - by KooiInc
    Just out of curiosity. It doesn't seem very logical that typeof NaN is number. Just like NaN === NaN or NaN == NaN returning false, by the way. Is this one of the peculiarities of javascript, or would there be a reason for this?

    Read the article

  • How can I plot NaN values as a special color with imshow in matplotlib?

    - by Adam Fraser
    example: import numpy as np import matplotlib.pyplot as plt f = plt.figure() ax = f.add_subplot(111) a = np.arange(25).reshape((5,5)).astype(float) a[3,:] = np.nan ax.imshow(a, interpolation='nearest') f.canvas.draw() The resultant image is unexpectedly all blue (the lowest color in the jet colormap). However, if I do the plotting like this: ax.imshow(a, interpolation='nearest', vmin=0, vmax=24) --then I get something better, but the NaN values are drawn the same color as vmin... Is there a graceful way that I can set NaNs to be drawn with a special color (eg: gray or transparent)?

    Read the article

  • Ecmascript 5 Date.parse for ISO 8601 test cases

    - by 4esn0k
    What results is right for next test cases? //Chrome Opera Firefox IE 9 Safari console.log(Date.parse("2012-11-31T23:59:59.000Z"));//1354406399000 NaN NaN 1354406399000 NaN console.log(Date.parse("2012-12-31T23:59:59.000Z"));//1356998399000 1356998399000 1356998399000 1356998399000 1356998399000 console.log(Date.parse("2012-12-31T23:59:60.000Z"));//NaN NaN NaN NaN 1356998400000 console.log(Date.parse("2012-04-04T05:02:02.170Z"));//1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 console.log(Date.parse("2012-04-04T24:00:00.000Z"));//NaN 1333584000000 1333584000000 1333584000000 1333584000000 console.log(Date.parse("2012-04-04T24:00:00.500Z"));//NaN NaN 1333584000500 1333584000500 NaN

    Read the article

  • removing pairs of elements from numpy arrays that are NaN (or another value) in Python

    - by user248237
    I have an array with two columns in numpy. For example: a = array([[1, 5, nan, 6], [10, 6, 6, nan]]) a = transpose(a) I want to efficiently iterate through the two columns, a[:, 0] and a[:, 1] and remove any pairs that meet a certain condition, in this case if they are NaN. The obvious way I can think of is: new_a = [] for val1, val2 in a: if val2 == nan or val2 == nan: new_a.append([val1, val2]) But that seems clunky. What's the pythonic numpy way of doing this? thanks.

    Read the article

  • Using exponential smoothing with NaN values

    - by Eric
    I have a sample of some kind that can create somewhat noisy output. The sample is the result of some image processing from a camera, which indicates the heading of a blob of a certain color. It is an angle from around -45° to +45°, or a NaN, which means that the blob is not actually in view. In order to combat the noisy data, I felt that exponential smoothing would do the trick. However, I'm not sure how to handle the NaN values. On the one hand, involving them in the math would result in a NaN average, which would then prevent any meaningful results. On the other hand, ignoring NaN values completely would mean that a "no-detection" scenario would never be reported. And just to complicate things, the data is also noisy in that it can get false NaN value, which ideally would be smoothed somehow to prevent random noise. Any ideas about how I could implement such an exponential smoother?

    Read the article

  • From NaN to Infinity...and Beyond!

    It is hard to believe that it was once possible to corrupt a SQL Server Database by storing perfectly normal data values into a table; but it is true. When one then tried to query this data; the values were unsupported and so data pages containing them were flagged as being corrupt....Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • convert string to float without silent NaN/Inf conversion

    - by Peter Hansen
    I'd like convert strings to floats using Python 2.6 and later, but without silently converting things like 'NaN' and 'Inf'. Before 2.6, float("NaN") would raise a ValueError. Now it returns a float for which math.isnan() returns True, which is not useful behaviour for my application. Here's what I've got at the moment: import math def get_floats(source): for text in source.split(): try: val = float(text) if math.isnan(val) or math.isinf(val): raise ValueError yield val except ValueError: pass This is a generator, which I can supply with strings containing whitespace-separated sequences representing real numbers. I'd like it to yield only those fields which are purely numeric representations of floats, as in "1.23" or "-34e6", but not for example "NaN" or "-Inf". Test case: assert list(get_floats('1.23 -34e6 NaN -Inf')) == [1.23, -34000000.0] Please suggest alternatives you consider more elegant, even if they involve "look before you leap" (which is normally considered a lesser approach in Python).

    Read the article

  • Make UILabel show "No results" instead of "nan"

    - by Mike Rychev
    I have a small app, where user can make some calculations and solve equations. For example, if in a square equation discriminant is less than zero, the x1 and x2 values are "nan", so when I assign x1 and x2 values to UILabels they show "nan" as well. Writing a lot of if's like if(D<0) [label setText:[NSString stringWithFormat: @"No solutions"]]; Doesn't help-there are too many cases. I want to check if after [label setText:[NSString stringWithFormat: @"%f", x]]; label's value is "nan", the label's value will be set to @"No solutions". Doing simple if(label==@"nan") { //code } doesn't help. Thanks in advance!

    Read the article

  • Per-pixel collision detection - why does XNA transform matrix return NaN when adding scaling?

    - by JasperS
    I looked at the TransformCollision sample on MSDN and added the Matrix.CreateTranslation part to a property in my collision detection code but I wanted to add scaling. The code works fine when I leave scaling commented out but when I add it and then do a Matrix.Invert() on the created translation matrix the result is NaN ({NaN,NaN,NaN},{NaN,NaN,NaN},...) Can anyone tell me why this is happening please? Here's the code from the sample: // Build the block's transform Matrix blockTransform = Matrix.CreateTranslation(new Vector3(-blockOrigin, 0.0f)) * // Matrix.CreateScale(block.Scale) * would go here Matrix.CreateRotationZ(blocks[i].Rotation) * Matrix.CreateTranslation(new Vector3(blocks[i].Position, 0.0f)); public static bool IntersectPixels( Matrix transformA, int widthA, int heightA, Color[] dataA, Matrix transformB, int widthB, int heightB, Color[] dataB) { // Calculate a matrix which transforms from A's local space into // world space and then into B's local space Matrix transformAToB = transformA * Matrix.Invert(transformB); // When a point moves in A's local space, it moves in B's local space with a // fixed direction and distance proportional to the movement in A. // This algorithm steps through A one pixel at a time along A's X and Y axes // Calculate the analogous steps in B: Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB); Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB); // Calculate the top left corner of A in B's local space // This variable will be reused to keep track of the start of each row Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB); // For each row of pixels in A for (int yA = 0; yA < heightA; yA++) { // Start at the beginning of the row Vector2 posInB = yPosInB; // For each pixel in this row for (int xA = 0; xA < widthA; xA++) { // Round to the nearest pixel int xB = (int)Math.Round(posInB.X); int yB = (int)Math.Round(posInB.Y); // If the pixel lies within the bounds of B if (0 <= xB && xB < widthB && 0 <= yB && yB < heightB) { // Get the colors of the overlapping pixels Color colorA = dataA[xA + yA * widthA]; Color colorB = dataB[xB + yB * widthB]; // If both pixels are not completely transparent, if (colorA.A != 0 && colorB.A != 0) { // then an intersection has been found return true; } } // Move to the next pixel in the row posInB += stepX; } // Move to the next row yPosInB += stepY; } // No intersection found return false; }

    Read the article

1 2 3 4 5 6 7  | Next Page >