Navigating The Hell of NaNs in Python (2024)

Navigating The Hell of NaNs in Python (1)I recently had a lot of headaches caused by NaNs. Every programmer knows what they are, and why they happen, but in my case, I did not know all of their characteristics or not well enough to prevent my struggle. In the hope of finding solutions and avoiding a bad headache, I looked further into the behaviour of NaNs values in Python. After playing with a few statements in Jupyter Notebook, my results were quite surprising and extremely confusing. Here is what I had using np.nan from Numpy.

np.nan in [np.nan] is True

So far so good, okay but …

np.nan == np.nan is False

Huh? And …

np.nan is np.nan is True

So what the hell is going on with NaNs in Python?

NaN stands for Not A Numberandisacommon missingdatarepresentation. It is a special floating-point value and cannot be converted to any other typethanfloat. It was introduced by the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754) before Python even existedandisusedinallsystemsfollowingthisstandard. NaN can be seen like some sort of data virus that infects all operations it touches.

None vs NaN

None and NaN sound similar, look similar but are actually quite different. None is a Python internal type which can be considered as the equivalent of NULL. The None keyword is used to define a null value, or no value at all. None is not the same as 0, False, or an empty string. It is a datatype of its own (NoneType) and only None can be … None. While missing values are NaN in numerical arrays, they are None in object arrays. It is best to check for None by using foo is None instead of foo == None which brings us back to our previous issue with the peculiar results I found in my NaN operations.

At first, reading that np.nan == np.nan is False can trigger a reaction of confusion and frustration. It looks weird, sounds really weird but if you give it a little bit of thought, the logic starts to appear and even starts to…

Navigating The Hell of NaNs in Python (2024)
Top Articles
6 Reasons Why Your Tomato Plant is Wilting and What to Do About It
How Much Do Wedding Flowers Cost? | Something Borrowed BloomsPremium Silk Flowers
Nerdwallet Chase
William G. Nolan - Baker Swan Funeral Home
ᐅ eGirl Kleidung kaufen: Wie ein eGirl aussehen so funktionierts!
Home Store On Summer
Het Musculoskeletal Clinical Translation Framework - FysioLearning
Mensenlinq: Overlijdensberichten zoeken in 2024
Teamsideline Manatee
Cpt 90677 Reimbursem*nt 2023
Keanu Reeves cements his place in action genre with ‘John Wick: Chapter 4’
Guardians Of The Galaxy Vol 3 Full Movie 123Movies
Duralast Battery H6-Dl Group Size 48 680 Cca
Pierced Universe Coupon
Hydro Quebec Power Outage Map
Telegram X (Android)
Bomei Massage
Busted Newspaper Randolph County Missouri
Milwaukee Nickname Crossword Clue
Sitel Group®, leader mondial de l’expérience client, accélère sa transformation et devient Foundever®
New York Rangers Hfboards
Nantucket Hdc
The Haunting Of A Dream House By Reeves Wiedeman
Andrew Davis Vsim
Rosekellyppv
8 30 Eastern Standard Time
Costco Gas Price City Of Industry
Bonduel Amish Auction 2023
Peak Gastroenterology Associates Briargate
Hannaford Weekly Flyer Manchester Nh
Does Publix Have Sephora Gift Cards
Bx9 Bus Schedule
Kidcheck Login
Hyvee Workday
Pull And Pay Middletown Ohio
John Wick 4 Showtimes Near Starlight Whittier Village Cinemas
Dead Island 2 im Test: Mit dieser Qualität hätte ich nach neun Jahren nicht gerechnet!
Spn 102 Fmi 16 Dd15
Ixl Sbisd Login
Lkq Pull-A-Part
12000 Divided By 40
Sunset Time Yesterday
Directions To Truist Bank Near Me
Grupos De Cp Telegram
Enterprise Car Sales Jacksonville Used Cars
Let's Take a Look Inside the 2024 Hyundai Elantra - Kelley Blue Book
The Whale Showtimes Near Cinépolis Vista
Entegra Forum
Z93 Local News Monticello Ky
236 As A Fraction
Rabbi Raps
Mugshots In Waco Texas
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 6307

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.