Dr. Joshua Vaughan
joshua.vaughan@louisiana.edu
http://www.ucs.louisiana.edu/~jev9637/
In this notebook, we'll simply be testing that all the tools that we'll be using this semester have been installed correctly, while hopefully providing a simple first exercise with the Jupyter Notebook.
We'll first place a "watermark" that will display our system information. You should have followed the instructions on the lab handout to install this package. You can see more information about this package at:
https://github.com/rasbt/watermark
If you haven't yet installed it, you can by issuing the command below from a terminal window:
conda install -c conda-forge watermark
Many more examples of its use are included in this example Jupyter Notebook.
# We first need to tell the Jupyter Notebook to load the extension
%load_ext watermark
# The base usage will tell us information about our machine and the version of Python we're using
%watermark
2018-08-15T17:58:41-05:00 CPython 3.6.2 IPython 6.1.0 compiler : GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57) system : Darwin release : 17.7.0 machine : x86_64 processor : i386 CPU cores : 8 interpreter: 64bit
We can also use the options in the package to tell us about versions of specific python packages. In this case, we'll check the versions of the NumPy, SciPy, matplotlib, Jupyter Notebook, and Control packages.
%watermark -v -m -p numpy,scipy,control,notebook,matplotlib
CPython 3.6.2 IPython 6.1.0 numpy 1.13.3 scipy 1.0.0 control 0.7.0 notebook 5.0.0 matplotlib 2.0.2 compiler : GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57) system : Darwin release : 17.7.0 machine : x86_64 processor : i386 CPU cores : 8 interpreter: 64bit
The output of that command look similar to the first, but with the versions of the NumPy, SciPy, matplotlib, Jupyter Notebook, and Control packages indicated as well. Now, let's run some simple commands to double-check that everything is working.
We'll first import NumPy, the set up the notebook for plotting using the matplotlib library.
# Grab all of the NumPy functions with namespace np
import numpy as np
%matplotlib inline
# Import the plotting functions
import matplotlib.pyplot as plt
Let's plot an array of random numbers. We'll use the numeric portion of our CLID's as a "seed" for the random number generator. This will make the string of numbers i.) repeatable and ii.) unique to the seed value, meaning your plots will be unique to your CLID numerals.
In the first code block below, change 1234 to be the numeric portion of your CLID. This creates a random number generator with that as the seed. Eliminate the leading zeros from the number, so that if your ULID is C00123456
, you would change the seed to be 123456
.
# Change 1234 to match the numeric portion of your ULID
my_random_generator = np.random.RandomState(seed=123456)
Now, we'll use this generator to generate an array of 500 elements and plot them.
my_random_numbers = my_random_generator.rand(500) # Generate 500 random numbers
# Now, we'll plot them. Here, we'll just use the matplotlib defaults.
# By default, no axis labels, etc are included.
# Later, we'll generate nicer plots by modifying some of those defaults.
plt.plot(my_random_numbers)
[<matplotlib.lines.Line2D at 0x11fce3da0>]
Now, let's import the scipy, sympy, and Control modules, just to check that they will load. If there were no errors from the:
%watermark -v -m -p numpy,scipy,control,notebook,matplotlib
command above, then they should load without any issue.
import control # This will import the control library. We'll need to preface any commands from it with control.
import scipy # This will import the scipy libary. We'll almost never import this entire library again.
import sympy # This will import the sympy libary. We'll almost never import this entire library again.
Code is licensed under a 3-clause BSD style license. See the licenses/LICENSE.md file.
Other content is provided under a Creative Commons Attribution-NonCommercial 4.0 International License, CC-BY-NC 4.0.
# This cell will just improve the styling of the notebook
from IPython.core.display import HTML
import urllib.request
response = urllib.request.urlopen("https://cl.ly/1B1y452Z1d35")
HTML(response.read().decode("utf-8"))