Introduction to python#
The goal of this section is to introduce python if you have little to no experience with it. We want to get you up to speed with the skills needed for this course. If you feel comfortable enough with python, you can skip this. Otherwise, it is recommended that you walk through the links and complete the four assignments.
We can study exploration well using computer simulations. And we will do so, rather a lot. Our examples all happen in python, a popular programming language. Rather than do duplicate work and write another learning python tutorial, here are some links to begin learning, or to refresh yourself.
If you have never programmed before, or programmed python before, this introductory class from the UCSD Cognitive Science department is as a good a beginner’s introduction as any.
** Note: There are various mentions and references in this online book for this class as it was taught live. They are a little distracting, but the material is good, so I’d ignore this cruft.
If you have programmed python before but could use a refresher, this tutorial seems good to me. It starts assuming you know some basic programming ideas.
There are three other tools in python thta we will need. One is a library called numpy, which is the core for all scientific work in python. A nice introduction for this can be found below. (The book comes from a generally excellent reference for using python in data science.)
Python Data Science Handbook - chapter 2
We will also use a visualization / plotting library called matplotlib, which you can try our here:
Python Data Science Handbook - chapter 4
Finally we will be using jupyter notebooks. There are a useful way to mix python code, with explanatory text, with images and plots. This whole book is written in notebooks. So are all the tutorials above!
A very easy way to run notebooks, and to even understand what they are, is to use an online service, like Google’s colaboratory. It’s a bit like Google Docs, but for python code.
At the top of every page and assignment in this book is an open in collab button. It looks like an infinity sign, sort of. If you click that button (and are on the internet) the page will open up a live python session, and you can get right to work. For more:
Self-paced practice#
Assignment 1#
Read through either the Cogs19 or Whirlwind tour links. If you need to read deeply, and try things out in Google Colab.
Assignment 2#
Read through the introductions to numpy and matplotlib. If you need to read deeply, and try things out in Google Colab.
Assignment 3#
Read through the What is colaboratory? introduction. Run every cell in it. See what happens.
Assignment 4#
Open this assignment in a Colab. In the cell below: import numpy, matplotlib, and plot a time series of 100 normally distributed numbers (in black, as a line).
# (The magic '%' below will put the plot nicely in place)
%matplotlib inline
# Put your code here.