Please explain ! I can't even reproduce it on other computer.
Asked
Active
Viewed 145 times
1 Answers
0
Sorting is based on the idea that the values being sorted form a total order. A total order requires several properties be met, including
- for any two values
a
andb
, exactly one ofa < b
,a == b
, ora > b
is true - the relations are transitive:
a < b
andb < c
implies thata < c
.
Knowing that we have a total order, we can assume that an sorted order exists, and that we can find it using O(n lg n) comparisons. In the absence of this assumption, we need to make O(n^2) comparisons to even determine if a sorted order exist, let alone produce one.
Floating point values with np.nan
do not form a total order.
All three comparisons np.nan < x
, np.nan == x
, and np.nan > x
are false no matter what x
is. As a result, there is no "correct" place for np.nan
in list; it all depends on which comparisons are made and when.

chepner
- 497,756
- 71
- 530
- 681