Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

The math module includes a few statistical math functions for good measure, as shown in Table 5.6.


TABLE 5.6 Python Statistical Math Functions

The error function is a core computation used in statistical analysis equations. You need it to compute
the normal cumulative distribution and the statistical Q-function. You need the complementary (or
inverse) error function to calculate the normal quartile of a statistical series.


Using the NumPy Math Libraries


Besides the host of functions available in the standard math module, many engineers, scientists, and
statisticians who use fancy mathematical calculations have created and shared their own extended
Python math modules.


One of the core Python libraries for advanced mathematical computing is NumPy. The NumPy
module provides methods for multidimensional array manipulations, which are required for many
advanced scientific and statistical calculations. It consists of the following:


A multidimensional array object class
Methods for array manipulation

The NumPy multidimensional array objects are somewhat different from standard Python lists or
tuples in that you can easily use them in mathematical calculations that require arrays. Python handles
the array objects differently from lists and tuples. The following section walks through how to use the
NumPy features.


NumPy Data Types


The NumPy module provides five core data types that you can use to store data in arrays:


bool—Booleans
int—Integers
uint—Unsigned integers
float—Floating-point numbers
complex—Complex numbers

Within those five core data types, you can also specify a bit size at the end of the data type name, such
as int8, float64, or complex128. If you don’t specify the bit size, Python will assume the bit
size based on the CPU platform (such as 32-bit or 64-bit).


To use the NumPy module functions in your programs, just import the numpy module, however, you
may have to be patient, as it can take some time to load all of the library methods!


Creating NumPy Arrays


The Raspberry Pi Python v3 installation already includes the NumPy module, so you can write your

Free download pdf