2. Virtual what now?
VirtualBox is a program to create and manage Virtual Machines (operating systems)
Great way to create sandboxed environments (to play around)
… lets us mess around with linux
www.virtualbox.org
3. linux? ubuntu?
Linux is an operating system
… created by Linus Torvals in 1991
… written as Free & Open Source Software
4. linux? ubuntu?
Linux is an operating system
… created by Linus Torvals in 1991
… written as Free & Open Source Software
http://www.stickycomics.com/computer-update/
… all software is free to install
… very safe and secure
… soooo many options
5. linux? ubuntu?
Ubuntu is a linux distribution (a.k.a. flavour)
XFCE is a desktop environment (user interface)
xubuntu simple, lightweight & user-friendly linux distro.
6. linux? ubuntu?
Ubuntu is a linux distribution (a.k.a. flavour)
XFCE is a desktop environment (user interface)
xubuntu simple, lightweight & user-friendly linux distro.
≠ ≠
7. Python!!!
https://en.wikipedia.org/wiki/Guido_van_Rossum
Created in the 1980’s by Guido van Rossum (the BDFL)
… an easy and intuitive language just as powerful as major competitors
… open source so anyone can contribute to its development
… code that is as understandable as plain English
… suitability for everyday tasks, allowing for short development times
(goals for DARPA funded project “Computer Programming for Everybody”)
9. Python in (neuro)science…
Python is a general purpose programming language
Python is free & open source → lots of “community” modules available
Why not MATLAB, or R???
10. python 2 vs. python 3
“Python 2.x is legacy, Python 3.x is the present and future of the language.”
… how the print statement works … symbols used for division
… mostly small details
… better library support and older modules in python 2.x
… python 2 (more specifically 2.7) FTW!!!
http://learntocodewith.me/programming/python/python-2-vs-python-3/
11.
12. The plan!
Basics: types, operations & calculations
Basics: conditionals & iteration
Basics: lists, tuples, dictionaries
Basics: writing functions
Reading & writing files: opening, parsing & formats
Working with numbers: numpy & scipy
Making plots: matplotlib & pylab
… if you guys want more after all of that …
Writing better code: functions, pep8, classes
Working with numbers: Numpy & Scipy (advanced)
Other modules: Pandas & Scikit-learn
Interactive notebooks: ipython & jupyter
Advanced topics: virtual environments & version control
13. … some arbitrary examples
http://matplotlib.org/gallery.html & http://scikit-learn.org/
14.
15. Welcome to neuropy@xubuntu!!!
username: neuropy
password: 1234 (for admin stuff)
i’ve installed: only some virtual machine goodies…
Installing software in xubuntu
… via the software center
… let’s install gedit
16. command line warrior, step 1…
Navigating the linux command line:
… cp source-file destination-file → copy
… cp -r source-folder destination-folder → copy
… mv source destination → move
… ls → list note: “..” means
“up one folder”
… cd folder → change directory
Manipulating files & folders
… rm file → remove
… rm -r folder → copy
… cat file → show contents
some other random commands…
… head file → cat first 20 lines
… tail file → cat last 20 lines
17. command line pythonista, step 1…
Writing helloworld.py
… open gedit, let’s write a simple “Hello world” program.
---- file contents ----
print “Hello world”
… save it somewhere (let’s say, the desktop)
To run the file:
… python helloword.py
18. command line pythonista, step 1…
Writing helloworld.py
… open gedit, let’s write a simple “Hello world” program.
---- file contents ----
print “Hello world”
… save it somewhere (let’s say, the desktop)
To run the file:
… python helloword.py
error messages are your friends!!!
(you’ll be seeing a lot of them!)
19. interactive python
let’s fire up an interactive shell:
… in the command line, type “python” (and hit enter)
… each command is interpreted on the fly!
… >>> print “Hello python!”
“Hello python!”
>>>$
pythonlinux
20. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
21. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
more maths with python: floats
>>> d = 1.2 + 1.3
>>> print d
2.5
22. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
more maths with python: floats
>>> d = 1.2 + 1.3
>>> print d
2.5
more maths with python…
>>> 4 ** 3
64
>>> 5 / 2
23. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
more maths with python: floats
>>> d = 1.2 + 1.3...
>>> print d
2.5
more maths with python…
>>> 4 ** 3
64
>>> 5 / 2
2
24. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
more maths with python: floats
>>> d = 1.2 + 1.3...
>>> print d
2.5
more maths with python…
>>> 4 ** 3
64
>>> 5 / 2
2 WTF?!?
25. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
more maths with python: floats
>>> d = 1.2 + 1.3...
>>> print d
2.5
more maths with python…
>>> 4 ** 3
64
>>> 5 / 2
2 WTF?!?
>>> 5.0 / 2.0
2.5
python 2 vs. python 3
… in python 2: “/” does int or float
division.
… fixed in python 3: “/” always does
“normal” division
26. interactive python: a calculator
basic maths with python: integers
>>> 1 + 2 * 3
7
>>> a = 5
>>> b = 10
>>> c = a * b
>>> print c
50
>>> a + b
15
more maths with python: floats
>>> d = 1.2 + 1.3...
>>> print d
2.5
more maths with python…
>>> 4 ** 3
64
>>> 5 / 2
2 WTF?!?
>>> 5.0 / 2.0
2.5
27. myfirstprogram.py
lets start a new file myfirstprogram.py
---- file contents ----
from __future__ import division
# the first line fixes the “division” problem in python 2
# this is a comment. Comments start with “#”, and are not interpreted!
name = “Marc” # comments can also go after stuff
print “Hello”, name # print multiple things in one line with “,”
a = 20
b = 15
c = a * b
print “Some numbers:”, a, b, c
print “Let’s make sure division is working OK”
print a, “divided by”, b, “=”, a / b
28. userintercation.py
lets start a new file userinteraction.py
also, let’s see the difference between integers and strings
---- file contents ----
from __future__ import division
# raw_input asks the user for input
name = raw_input(“What is your name?”)
print “Hello”, name
# we need to convert numbers to int (or float) to do maths
a = int(raw_input(“Write a number, any number:”))
b = int(raw_input(“Gimme another one:”))
print a, “plus”, b, “=”, a + b
print “I can do addition!”
29.
30. take home to christmas messages:
the linux command line:
… ls, cd, cp, mv & rm
… also cat, head & tail
two ways to use python:
… from a file: python filename.py
… interactively: python (enter) → “>>>”
basic math operators:
… +, -, *, / and **
… remember python 2 is strange with “/”
… just use “from __future__ import division” and you’ll be fine!
asking for user input (and converting strings to integers)
… name = raw_input(“And, are we liking python yet?”)