Mathematics and Numbers

In addition to the built-in int, float, and complex numbers, the library provides the decimal.Decimal and fractions.Fraction numbers. Three numeric libraries are available: math for the standard mathematical functions, cmath for complex number mathematical functions, and random which provides many functions for random number generation; these modules were introduced in Chapter 2.

Python's numeric abstract base classes (classes that can be inherited from but that cannot be used directly) are in the numbers module. They are useful for checking that an object, say, x, is any kind of number using isinstance(x, numbers.Number), or is a specific kind of number, for example, isinstance(x, numbers.Rational) or isinstance(x, numbers.Integral).

Those involved in scientific and engineering programming will find the third-party NumPy package to be useful. This module provides highly efficient n-di-mensional arrays, basic linear algebra functions and Fourier transforms, and tools for integration with C, C++, and Fortran code. The SciPy package incorporates NumPy and extends it to include modules for statistical computations, signal and image processing, genetic algorithms, and a great deal more. Both are freely available from

Was this article helpful?

0 0

Post a comment