📚 The CoCalc Library - books, templates and other resources
License: OTHER
Kernel: Python 3
Rolling operators
Code examples from Think Complexity, 2nd edition.
Copyright 2019 Allen Downey, MIT License
In [1]:
Exercise: Write a Python function that takes a sequence and an integer k
and computes the "rolling sum", which is sum of each subset of k
consecutive elements. For example:
You can use any language features you want: pure Python, NumPy, Pandas, or SciPy.
In [2]:
In [3]:
Exercise: Rewrite the previous example using a list comprehension.
In [4]:
In [5]:
Exercise: Write a version using np.correlate
.
In [6]:
In [7]:
Exercise: Write a version using scipy.signal.correlate
.
In [8]:
In [9]:
In [10]:
Exercise: Write a version using pd.Series.rolling()
.
In [11]:
In [12]:
In [13]:
In [14]:
In [15]:
In [16]: