Time for action – checking the array order

Let's check whether one array is strictly greater than another array:

  1. Call the assert_array_less() function with two strictly ordered arrays:
    print("Pass", np.testing.assert_array_less([0, 0.123456789, np.nan], [1, 0.23456780, np.nan]))

    The result is as follows:

    Pass None
    
  2. Call the assert_array_less() function:
    print("Fail", np.testing.assert_array_less([0, 0.123456789, np.nan], [0, 0.123456780, np.nan]))

    The test raises an exception:

    Fail
    Traceback (most recent call last):
      ...
        raise AssertionError(msg)
    AssertionError:
    Arrays are not less-ordered
    
    (mismatch 100.0%)
     x: array([ 0.        ,  0.12345679,         nan])
     y: array([ 0.        ,  0.12345678,         nan])
    

What just happened?

We checked the ordering of two arrays with the assert_array_less() ...

Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.