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.

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.