To determine NaN

Asked 2 years ago, Updated 2 years ago, 136 views

float('nan') returns float type nan without making an error If you try to handle something with this value, you get all the strange results.

I'd like to check 'nan' as a conditional statement What should I do?

python math

2022-09-22 22:26

1 Answers

Math.isnan() determines whether float is NaN or not.

import math
x=float('nan')
math.isnan(x)

It checks whether float is NaN or not as same as math.isnan().

import numpy
x=float('nan')
numpy.isnan(x)

According to IEEE standard, NaN value is always false when comparing NaN value. Use this to define a function.

def isNaN(num):
    return num != num
x=float('nan')
isNaN(x)


2022-09-22 22:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.