Back

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

Is it possible to set an element of an array to NaN in Python?

Additionally, is it possible to set a variable to +/- infinity? If so, is there any function to check whether a number is infinity or not?

1 Answer

0 votes
by (106k points)

Yes, it can be done you just need to cast from string using float():

>>> float('NaN') 

nan 

>>> float('Inf') 

inf 

>>> -float('Inf') 

-inf 

>>> float('Inf') == float('Inf')

 True 

>>> float('Inf') == 1 

False

Browse Categories

...