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 – comparing objects


Suppose you need to compare two tuples. We can use the assert_equal() function to do that.

Call the assert_equal() function:

print("Equal?", np.testing.assert_equal((1, 2), (1, 3)))

The call raises an error because the items are not equal:

Equal?
Traceback (most recent call last):
  ...
    raise AssertionError(msg)
AssertionError:
Items are not equal:
item=1

 ACTUAL: 2
 DESIRED: 3

What just happened?

We compared two tuples with the assert_equal() function—an exception was raised because the tuples were not equal to each other.