Book Image

Learning NumPy Array

By : Ivan Idris
Book Image

Learning NumPy Array

By: Ivan Idris

Overview of this book

Table of Contents (14 chapters)
Learning NumPy Array
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Smoothing functions


Smoothing can help us get rid of noise and outliers in raw data. This, for instance, makes it easier to spot trends in the data. NumPy provides a number of smoothing functions.

Note

These functions can calculate weights in a sliding window as we did in the previous example (for more background information, visit http://en.wikipedia.org/wiki/Window_function).

These functions, except the kaiser function, require only one parameter—the size of the window, which we will set to 22 for the middle cycle of the sunspot data. The kaiser function also needs a beta parameter. With this parameter, the kaiser function can mimic the other functions.

The NumPy documentation recommends a starting value of 14 for the beta parameter, so that is what we are going to use too. The code is straightforward and given as follows (the data here is limited to the last 50 years only for easier comparison in the plots):

import numpy as np
import sys
import matplotlib.pyplot as plt

def smooth(weights...