4,382 questions
6
votes
1
answer
212
views
MSVC doesn't follow NAN convention
The following code prints
1.000000 when compiled with gcc (trunk)
1.000000 when compiled with clang (trunk)
NAN when compiled with msvc (latest)
#include <stdio.h>
#include <math.h>
#...
2
votes
1
answer
59
views
Making matplotlib boxplot include columns with NaN values
I've been trying to plot a data frame as a box plot using matplotlib. My data frame looks something like this:
9-1 9-2 9-3 9-4 9-5
0 23 16.0 18.0 18.0 26
1 27 18.0 20.0 17.0 33
...
-4
votes
1
answer
173
views
Why am I getting "nan" when I try to overload the modulo operator in C++? [closed]
I am trying to overload the % operator in C++ to make it do division instead of modulo. For example, 5 % 4 should give me 1.25 after overloading.
But I get "nan". Why?
This is the code I ...
1
vote
2
answers
132
views
In pandas, how to write the word "nan" as string with to_excel?
I have the reverse problem as described in Prevent pandas from interpreting 'NA' as NaN in a string.
I work with older English text data and want to write the word "nan" (i.e. Modern ...
1
vote
2
answers
158
views
Can I tell my compiler that a floating-point value is not NaN nor +/-infinity?
I'm writing a C function float foo(float x) which manipulates a floating-point value. It so happens, that I can guarantee the function will only ever be called with finite values - neither NaN's, nor +...
0
votes
1
answer
46
views
How to create a custom Number type in Groovy behave like a special "NaN-like"
I want to create a custom Number type in Groovy that accepts null, empty strings, and any input valid for the BigDecimal constructor. When given null or an empty string, it should behave like a ...
0
votes
0
answers
105
views
Pandera validation behavior for NaN failure cases
Suppose we use a minimal example for a panderas dataframe-wide validation (cf. this Stackoverflow post):
import numpy as np
import pandas as pd
import pandera as pa
dataframe = pd.DataFrame({'...
2
votes
2
answers
112
views
Can clang -ffast-math optimize away comparison between quiet_NaN and float?
I noticed that the following program optimizes to no instructions at all on recent versions of clang, with -ffast-math and -O1 and higher:
#include <cassert>
#include <limits>
int main() {...
1
vote
2
answers
49
views
I'm training a image captioning model and getting Nan in my loss
I'm training a image caption model using TensorFlow. I'm using Flickr 8K dataset and I have used ResNet50 to get the encoding of all my images shaped as (m,49,2048) and stored them for training. I ...
0
votes
2
answers
93
views
Python 3 unit test
1st: I want to write a function "div" that takes two numbers as parameters and returns the quotient of the first number divided by the second number. and need to use a try-except statement ...
2
votes
1
answer
131
views
Why does pd.isnull behave differently on DataFrame vs. single element?
I'm noticing an inconsistency in how pd.isnull behaves.
Given that pd.isnull('nan') returns False, but pd.isnull(float('nan')) returns True, I would have expected that applying pd.isnull to a ...
1
vote
0
answers
37
views
max() output depends on order when nan is present [duplicate]
I am puzzled by this behaviour of Python's max() function:
>>> a = 100
>>> n = float("nan")
>>> a
100
>>> n
nan
>>> max(a, n)
100
>>> ...
0
votes
1
answer
114
views
Looping through a dataframe column to replace NaN values with values that aren't null:
The three columns on the left are day month, and year. I am trying to fill in NaN values in the last column which I am calling 'C'. For each week of each month there is one non-empty value in the last ...
1
vote
2
answers
105
views
How to erase segments where NaN values in a plot [closed]
EDIT: I found the issue. Some lines were missing, which led to these unwanted segments on the graph. I was able to "erase" these segments by filling missing dates with NaN.
I have a date ...
-4
votes
1
answer
111
views
Is there an objective reason why NaN is a number? [duplicate]
I know this question first sounds like an opinionated question, but I'm not seeking for personal opinions, because I could give my opinion too.
It's also not a duplicate of Why does typeof NaN return &...
1
vote
1
answer
99
views
Why is the p5.js console warning me that some of my variables are NaN?
I'm pretty new to coding, and I've been learning p5.js for a couple of weeks. I'm trying to write some code that will draw arcs of circles between evenly-spaced points on the top and right-hand edges ...
0
votes
1
answer
50
views
How to prevent non-numeric characters being put inside an input box
I am new to TypeScript and currently I am designing a BMR calculator. I have created a handleNumericInput function that only allows numbers to be accepted inside an input box but the problem is when I ...
0
votes
0
answers
32
views
RocketPy Error: multiple parachutes triggering simultaneously
I'm doing some Monte Carlo simulations in RocketPy. I am trying to simulate what a rocket launch that uses 2 parachutes; a drogue and a main parachute. I think this is a simple solution, but for ...
0
votes
0
answers
41
views
Pytorch Conv layer produces nan gradients, regardless of the input
I am training a PRO gan network based on this github. For those of you not familiar don't worry, the network architecture will not play a serious role.
I have this input convolutional layer, that ...
0
votes
1
answer
70
views
In python matplotlib, when plotting a multi-bar graph can I skip bars if the value is NaN so they do not appear?
I'm coding in Python using the library matplotlib to make a multi-bar graph, like a double-bar graph but I have 7 bars per category. I'm not sure what I have is necessarily the best way for me to plot ...
1
vote
1
answer
62
views
removing Nans from a 3D array without reshaping my data
I have a 3D array (121, 512, 1024) made up of frames of 512x1024 images.
The bottom several rows of the images have Nans which mess up my processing. I want to remove these and end up with something ...
1
vote
4
answers
142
views
How to make Numpy comparisons involving NaN to return NaN instead of False?
I'm doing comparisons (equality) of some series which have some NaN elements and numeric elements. I'd like every comparison involving a NaN to return NaN instead of False - what's the best Numpy ...
3
votes
1
answer
1k
views
suddenly getting "Operands are not aligned. Do `left, right = left.align(right, axis=1, copy=False)` before operating" error
In short, the code I was running two days ago worked perfectly. However, after attempting to mess with python (rookie mistake) I began receiving the following error.
isseyyohannes@Isseys-MBP ~ % /usr/...
0
votes
0
answers
27
views
Arima NaN Values
I have a dataset about the population from 1950 till 2100. The dataset was not stationary so I had to diff twice.
Differencing 1:
df_diff1 = df.diff() df_diff1 = df_diff1.dropna()
Differencing 2:
...
1
vote
1
answer
39
views
Fill Nans with rolling mean which is a combination of actual data + calculated rolling mean
I have tried to find the solution to this but havent been able to. So asking.
I have a dataset for which I wish to forecast values for future dates for groups within the dataset. The goal would be to ...
1
vote
1
answer
55
views
pandas fails to hide NaN entries from stacked line graphs
Say I have the following data:
Date,release,count
2019-03-01,buster,0
2019-03-01,jessie,1
2019-03-01,stretch,74
2019-08-15,buster,25
2019-08-15,jessie,1
2019-08-15,stretch,49
2019-10-07,buster,35
2019-...
2
votes
1
answer
74
views
Matlab mldivide returns NaN when there are multiple solutions
I have two matrices:
A = [ -1 0 0;
1 1 -1;
0 -1 1 ];
B = [-1; 0; 1];
and I want to solve the following equation:
Ax=B
when I use mldivide function I get a matrix of NaNs
X = mldivide(...
1
vote
2
answers
91
views
How to propagate numpy.nan through comparisons in Pandas
Let's say
df = pd.DataFrame({'A': [1, 3, np.nan]})
df['B'] = df['A'] > 2
I want this to give
A B
0 1.0 False
1 3.0 True
2 NaN NaN
but it gives
A B
0 1.0 False
1 3....
1
vote
1
answer
37
views
Pandas Dataframe fill with last value base on multiple condition [duplicate]
Suppose I have a DataFrame with some NaNs:
result
0 1
1 NaN
2 NaN
3 1
4 NaN
5 2
6 2
7 NaN
8 1
What I need to do is replace every NaN with the ...
3
votes
4
answers
179
views
Stripna: Pandas dropna but behaves like strip
It is a pretty common occurrence to have leading and trailing NaN values in a table or DataFrame. This is particularly true after joins and in timeseries data.
import numpy as np
import pandas as pd
...
0
votes
1
answer
34
views
tf.nn.sparse_softmax_cross_entropy_with_logits() output with nan
I am trying to get Mask-RCNN to run with tensorflow. The only variant so far where the training runs without any error messages (e.g. TypeError: unhashable type: 'ListWrapper'), comes from here: https:...
0
votes
2
answers
95
views
Reading a text file with a hh:mm:ss mixed with floats
I have a txt file like this :
index timestamp polarisation current (A) signal (V) head temperature (°C) head relat.humidity (%RH) MUGS temperature (°C) laser voltage (V) laser current (...
0
votes
0
answers
24
views
Double values for triangle angles returning as NaN if 2+ side lengths are the same
I'm trying to write a program that will calculate the angles of a triangle using the side lengths (via the Law of Cosines, Law of Sines, and Triangle Sum Theorem). It works just fine if all the side ...
2
votes
1
answer
63
views
Using python pandas to read excel column that has a formula extracting year from date and getting NaN for all rows but Header
I have an excel sheet where column A is filled with Date/Time and Column N is extracting just the year from the date, eg "=YEAR(A2)". I am trying to use some form of python, Openpyxl, Pandas ...
1
vote
1
answer
112
views
How to plot bar graphs with pandas using cut function and interval when NaNs are involved?
I'm wrestling with the following:
I have a dataframe with 2 columns of float values that may include NaNs.
For example:
In [5]: df = pd.DataFrame({'vals1': [10,20,25,15,np.nan, 2], 'vals2': [5, 11, 12,...
1
vote
1
answer
75
views
Pandas missing value representation in aggregated dataframe
When applying an aggregation to a grouped pandas DataFrame, the aggregated output appears to contains different values for aggregated all-missing-value-columns, depending on the type of the dataframe ...
0
votes
0
answers
66
views
best way to fill nans, getting the mean from multiple columns
I have a dataframe with reviews of restaurants. a columns "description sentiment" has been assigned a score ranging from -1.00 - +1.00. Some of the rows are 0 (due to some other factors in ...
1
vote
2
answers
265
views
Python set does not remove duplicate NaNs
Applying set() to a list containing multiple NaN values usually removes duplicate NaN entries.
Example:
set([np.nan, 5, np.nan, 17, 5, np.nan, 23])
yields:
{5, 17, nan, 23}
However, I now have a ...
2
votes
2
answers
127
views
ClassifierChain with Random Forest: Why is np.nan not supported even though Base Estimator handles it?
I'm working on a multilabel classification problem using the ClassifierChain approach with RandomForestClassifier as the base estimator. I've encountered an issue where my input matrix X contains np....
0
votes
1
answer
66
views
Pandas avoid element-wise NaN check for lists [duplicate]
I have a dataframe with columns containing both single NaNs, as well as lists which may contain NaN elements. Example:
df = pd.DataFrame({'A': [[1, 2, 3], np.nan, [7, np.nan, np.nan], [4, 5, 6]]})
I ...
0
votes
0
answers
73
views
Nan values are generating while interpolating data over 800 hpa using wrf python but working in 300,500
i am working on netcdf file and interpolating data for geopotential height 850hpa , 700hpa, 500hpa and 3oohpa
height =getvar(ncfile, 'z', timeidx=i)
pressure=getvar(ncfile,'pressure',timeidx=i)...
3
votes
1
answer
143
views
Clang float infinity divided by infinity produces different result with optimization flag
I just discovered that when dividing float infinity by itself, results in a different NaN on clang when compiling with any optimization option.
std::numeric_limits<float>::infinity()/std::...
0
votes
3
answers
75
views
Indexing changing the whole pandas DataFrame
I am kind of surprised by the behaviour of indexind this post they solved an initial doubt about accesing the rows that have NaNs values in them, but I see that when I omit the
.any(axis=1)
And just ...
1
vote
1
answer
367
views
Loss becomes Nan after attention_mask is added to the model while fine-tuning gemma2
I was trying to fine-tune gemma2 2b model on my own dataset for sequence classification tasks. But when I was testing the model, I found that after I plugged in the attention_mask to the model, the ...
4
votes
1
answer
151
views
Polars - unexpected behaviour when using drop_nans() on all columns
I have a simple Polars dataframe with some nulls and some NaNs and I want to drop only the latter. I'm trying to use drop_nans() by applying it to all columns and for whatever reason it replaces NaNs ...
0
votes
0
answers
52
views
LinAlgError: Array must not contain infs or NaNs
I am trying to put it in VAR to forecast...
data_n = yf.download("SPY",start="2022-09-01",end="2024-08-20",interval="1D")
data_n = data_n[["Close",&...
0
votes
1
answer
48
views
matplotlib graphs: how to connect with lines points if there are emply values in a column
I have graph with multiple parameters which I take from one big dataframe.
For one of parameters there are a few points only, rest values are empty (I can make them NAN or zero).
How can I connect ...
-2
votes
1
answer
52
views
why does it always executing the else block of code? [duplicate]
I was trying to make an isNaN() function that checks the user's input if its a NaN or not, but it always skips the the first condition whatever the user's input is.
function isNaN() {
let value = ...
1
vote
1
answer
28
views
unique indexes for multiple nan values in python list
Say I have the following python list with some random strings and multiple nan values:
l = [1, 'str', ',,,,', math.nan, 'another_str', math.nan, math.nan, 'last_str']
What I would like to achieve is ...
1
vote
1
answer
395
views
Numpy 2 has a separate float64(nan) - how to get rid of it?
It appears that Numpy 2 introduced its own separate float64(nan) - different from np.nan. Now regression tests fail because while
>>> np.nan is np.nan
True
we now have
>>> np.nan is ...