Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

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() function.