Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Most languages have a NaN constant you can use to assign a variable the value NaN. Can python do this without using numpy?

1 Answer

0 votes
by (106k points)

You can assign a variable NaN in Python without NumPy with construct NaN numbers using Python's decimal module:

>>from decimal import Decimal 

>>b = Decimal('nan') 

>>print(b) 

NaN 

>>print(repr(b)) 

Decimal('NaN') 

>>>Decimal(float('nan')) 

Decimal('NaN') 

>>> import math 

>>> math.isnan(b) 

True

The math.isnan(...) will also work with Decimal objects.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Sep 20, 2019 in Python by Sammy (47.6k points)
+1 vote
1 answer
0 votes
1 answer
0 votes
2 answers
asked Jul 13, 2019 in Python by Sammy (47.6k points)

Browse Categories

...