Book Image

Scientific Computing with Python - Second Edition

By : Claus Führer, Jan Erik Solem, Olivier Verdier
Book Image

Scientific Computing with Python - Second Edition

By: Claus Führer, Jan Erik Solem, Olivier Verdier

Overview of this book

Python has tremendous potential within the scientific computing domain. This updated edition of Scientific Computing with Python features new chapters on graphical user interfaces, efficient data processing, and parallel computing to help you perform mathematical and scientific computing efficiently using Python. This book will help you to explore new Python syntax features and create different models using scientific computing principles. The book presents Python alongside mathematical applications and demonstrates how to apply Python concepts in computing with the help of examples involving Python 3.8. You'll use pandas for basic data analysis to understand the modern needs of scientific computing, and cover data module improvements and built-in features. You'll also explore numerical computation modules such as NumPy and SciPy, which enable fast access to highly efficient numerical algorithms. By learning to use the plotting module Matplotlib, you will be able to represent your computational results in talks and publications. A special chapter is devoted to SymPy, a tool for bridging symbolic and numerical computations. By the end of this Python book, you'll have gained a solid understanding of task automation and how to implement and test mathematical algorithms within the realm of scientific computing.
Table of Contents (23 chapters)
20
About Packt
22
References

15.2.5 Assertion tools

In this section, we collect the most important tools for raising an AssertionError. We saw the command assert and three tools from unittest, namely assertAlmostEqual, assertEqual, and assertRaises. The following table (Table 15.1) summarizes the most important assertion tools and the related modules:

Assertion tool and application example

Module

assert 5==5

assertEqual(5.27, 5.27)

unittest.TestCase

assertAlmostEqual(5.24, 5.2,places = 1)

 unittest.TestCase

assertTrue(5 > 2)

unittest.TestCase

assertFalse(2 < 5)

unittest.TestCase

assertRaises(ZeroDivisionError,lambda x: 1/x,0.)

unittest.TestCase

assertIn(3,{3,4})

unittest.TestCase

assert_array_equal(A,B)

numpy.testing

assert_array_almost_equal(A, B, decimal=5)

numpy.testing

assert_allclose(A, B, rtol=1.e-3,atol=1.e-5)

numpy.testing

Table 15.1: Assertion tools in Python, unittest, and...