0

Please explain ! I can't even reproduce it on other computer.

enter image description here

1 Answers1

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

  1. for any two values a and b, exactly one of a < b, a == b, or a > b is true
  2. the relations are transitive: a < b and b < c implies that a < 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