Page last edited by Andrea Cuttone (ancu) 04/02-2014
Location
Learning objectives.
- Get Python installed on your system.
- Feel comfortable writing small scripts in python.
Program
Exercise 1. First we have to get your system in
shape for analyzing text.
- Get Python up and running on your system. We recommend that you install python via the Anaconda
distribution.
- Important (if you don't use Anaconda): We use
Python 2.7, so don't install python 3.1
- it will only cause you pain and suffering. Also - on Windows
make sure you install 32 bit Python, even if you're on a 64 bit
system (since NumPy only works with 32 bit).
- Important (if you don't use Anaconda): Make sure
you have the numpy, scipy, matplotlib & other prerequisites for
IPython Notebook up and running.
Exercise 2. You already know how to program (it's
a course requirement), but how's your Python doing? It's crucial
that you're feeling comfortable with IPython since we'll be using
it heavily throughout the course. Start up an
IPython Notebook and use it to solve the following exercises -
make sure you have plenty of explanatory text. [Details on how to
run an IPython Notebook can be found at the bottom of this
page]
- Create a list a that contains the
numbers from 1 to 100, incremented by one, using
the range function.
- Show that you understand slicing in Python by extracting a
list b with the numbers from 42 to 79
from the list created above.
- Using def, define a function that takes
as input a number x and outputs the number
multiplied by itself plus two f(x)
= x(x+2). Apply this function to every
element of the list b using
a for loop.
- Write the output of your function to a text file with one
number per line.
- Show that you know about strings typing
and understanding everything in
the example in http://learnpythonthehardway.org/book/ex6.html (include
this code in the Notebook).
Exercise 3. Plotting with Python. Work through this matplotlib tutorial, but substitute the
actual plotted values with your own data.
Advanced Exercise. If all of the above is easy for you,
work though this
advanced matplolib tutorial (pretty
version here). Note: You may hand in an
IPython Notebook with your own version of section 1.4.2.1-10 and
1.4.4.1-11 instead of Exercise 2 and
3.
IMPORTANT: Experience shows that
some of you will find Python difficult. If that's the case, please
learn how to code in Python. We recommend two options.
A) Either complete all of CodeAcademy's
excellent classes (1-21). Recommended option if you feel like a
total beginner.
B) Work throuth Exercise 1-40 of http://learnpythonthehardway.org/book/.
This option is better if you know a bit about programming but not
about Python.
Running IPython
Notebooks: Everything necessary to run IPython
Notebooks is included in the Anaconda distribution - simply type
"ipython notebook" at the terminal/command prompt,
and you'll get instructions on how open the notebook in your
browser. You may want to actually type "ipython notebook
--pylab inline" read more here [
link1,
link2].
Troubleshooting
Q: I get "ValueError: unknown locale: UTF-8" when running ipython
notebook
A: Open a terminal and execute the following:
echo export LC_ALL=en_US.UTF-8 >> ~/.profile
echo export LANG=en_US.UTF-8 >> ~/.profile
source ~/.profile
This page will be permanently deleted and cannot be recovered. Are you sure?
|