Python 3.4.3
IIT Bombay is leading the effort to popularise Python for Scientific Computing in India. This is part of the Free and Open source Software for Science and Engineering Education (http://fossee.in) project, supported by the National Mission on Education through ICT of MHRD.
IIT Bombay is using Spoken Tutorials (http://spoken-tutorial.org) to create learning material for FOSS. This is the main page for the organisation of the scripts required for Standard two day workshop we conduct on "Python for Scientific Computing" spoken tutorials.
Learners: UG/PG CSE/IT/CS students and CBSE high school students
Contents
Note: Each numbered topic corresponds to a single spoken tutorial. Each bulleted point corresponds to a command or topic that must be covered in the given spoken tutorial.
Module 1: Basic Plotting
Getting started with ipython
- Use Python 3.5.2
- Use Ipython version 5.1.0
- IPython is an enhanced interactive Python interpreter.
- Invoke the IPython interpreter
- Quit the IPython interpreter
- Navigate the IPython session history
- Use tab-completion to work faster.
- See the documentation of functions using question mark.
- Interrupt commands using Ctrl + C when we make an error.
- round command
Using the plot command interactively
- Use Python 3.4.3
- Use Ipython version 5.1.0
- Start IPython with pylab.
- ImportError if matplotlib is not installed
- clf() function
- Use the linspace function to create equally spaced points in a region.
- Find the length of sequences using len function.
- Plot mathematical functions using plot.
- Clear drawing area using clf.
- Usage of buttons in the UI of the plot window such as - save, zoom, move axis, back and forward and Home
Embellishing a plot
- Use Python 3.4.3
- Use Ipython version 5.1.0
- Modify the attributes of a plot
- Pass additional keyword arguments to plot command
- Add title to a plot using 'title' command.
- Incorporate LaTeX style formatting by adding a $ sign before and after the string.
- Label x and y axes using xlabel() and ylabel() commands.
- Add annotations to a plot using annotate() command.
- Get the limits of axes using xlim() and ylim() commands.
- Set the limits of axes using xlim() and ylim() commands.
Saving plots
- Use Python 3.4.3
- Use Ipython version 5.1.0
- Save plots using the savefig() function.
- Save the plots in different formats like
- ps
- png
- svg
- eps
Multiple plots
- Use Python 3.4.3
- Use IPython 5.1.0
- Draw multiple plots which are overlaid.
- Operations on individual plots.
- Use the figure command.
- Distinguish between multiple overlaid plots.
- Use the legend command.
- Serial number of the plot to select corresponding plot.
- Switch between the plots
- Saving individual plots.
Subplots
- Use Python 3.4.3
- Use IPython 5.1.0
- Creating subplots
- Switching between subplots.
- Subplot command
- Passing arguments to subplot command.
- First argument is the number of rows of subplots.
- Second argument is the number of columns of subplots
- Third argument specifies the serial number for subplot.
Additional features of IPython
- Use Python 3.4.3
- Use IPython 5.1.0
- Retrieve the history using %history command.
- View only a part of history by passing argument to %history command.
- Pass arguments to %history to get particular lines of code
- Save the required lines of code in required order using '%save' command.
- Use '%run -i' command to run a saved script.
Module 2: Plotting Experimental Data
loading data from files
- load data from file
- single column
- multiple columns separated by delimiter
- cat command
- loadtxt()
- columns separated by spaces
- columns separated by semi-colon
- unpack argument
- delimiter argument
- three columns of data
Plotting the data
- plotting data
- list
- list element-wise squaring
- plot data points
- clear plots
- errorbar function
- dots or filled circles in plot
- plot with red pluses
- explore documentation in ipython
- plot with errorbars
- using format argument
Other types of plots
- scatter plot
- scatter function
- scatter plot with various arguments
- logarithmic plot
- loglog function
- cat command
- loadtxt function
- unpack parameter of loadtxt
- linspace
- scatter versus plot
Plotting charts
- Use Python 3.4.3
- Use IPython 5.1.0
- To produce scatter plot
- Plot a pie chart using pie() function
- Plot a bar chart using bar() function
- Access the matplotlib online help
- Charts with line hatching
Module 4: Handling Large Data Files
Getting started with lists
- What is a list?
- Define List
- List index
- Create:
- List with elements
- Empty list
- List within a list
- Find out the list length using len function
- Access elements using their index numbers
- Append elements to list using the function append
- Delete element from list using the del and remove function
Getting started with for
- For loop syntax
- Example to use For loop
- Indentation in for loop
- Create blocks in python using for
- Iterate over a list using for loop
- How to get out of the block
- use of Range() function
- Range function in for loop
- How to use Python interpreter
- IPython interpreter to specify blocks
Getting started with strings
- What are strings?
- How are strings denoted in Python?
- String concatenation
- Multiply a string with an integer
- Accessing individual elements of a string
- Accessing elements of a string using negative indices
- Split() function
- Join() function
- Define a string in different ways
- Print a string repeatedly
Getting started with files
- Open a file
- Open() function
- Different Modes of opening a file
- Read() method
- Read the content of the file line by line
- Read the entire content of the file
- Append the lines of a file to a list
- Close a file
- Demonstration using a txt file
- Splitlines() method
Parsing data
- explain what is parsing
- strip (with strings)
- split (with strings)
- with delimiters
- specify space as delimiter
- specify space as delimiter
- with delimiters
- datatype conversion
- reading from files
- do the same problem done with loadtxt (for pendulum)
- basic parse sslc text
- do the same problem done with loadtxt (for pendulum)
Statistics
- mean
- summing
- summing
- median
- std
Module 5: Arrays and Matrices
Getting started with arrays
- why arrays
- speed - simply say
- array level operations
- speed - simply say
- creating arrays
- direct data
- list conversion
- homogeneous
- builtins - identitiy, zeros,
- direct data
- array operations
-
+ - * /
-
Accessing parts of arrays
- accessing individual elements
- changing individual elements
- slicing, striding
- image manipulation
Matrices
- creating matrices
- direct data
- list conversion
- builtins - identitiy, zeros,
- direct data
- matrix operations
- + - * /
- dot
- inv
- det
- eig
- norm
- svd
- + - * /
Least square fit
- show pendulum
- use loadtxt
- use loadtxt
- lstsq
Module 6: Python Language: Basics
Basic datatypes & operators
- int
- L, long
- L, long
- float
- repr, str
- repr, str
- complex
- boolean
- conversion functions
- sequence datatypes & mutability
- list available sequence datatypes
- string
- list
- tuple
- string
- mutability
- conversion
- common stuff
- len
- in
- max, min, sum, sorted, reversed
- accessing individual elements
- slicing, striding
- len
- list available sequence datatypes
I/O
Input Output in Python
Conditionals
- if, elif, else
- pass
Loops
- while
- for
- pass, break, continue
Module 7: Python Language: Datastructures
Manipulating lists
- concatenation
- slicing
- striding
- .sort
- sorted
- .reverse
- reversed
Manipulating strings
- upper, lower,
- replace
- slicing
- [::-1]
- reversed
- palindrome check
Getting started with tuples
- immutability
- tuple packing, unpacking
- a, b = b, a
- a, b = b, a
- accessing individual elements
- slicing, striding
Dictionaries
- empty
- filled
- accessing via keys
- .values(), .keys()
- in
- iteration
Sets
Sets
About sets in python
Module 8: Python Language: Advanced
Getting started with functions
- defining function
- arguments
- docstrings
- return values
- can return multiple values
- code reading exercises
Advanced features of functions
- default arguments
- keyword arguments
- built-in functions show off
Using python modules
- scipy
- pylab
- sys
Writing python scripts
- import
Testing and debugging
Testing and debugging
Handling Errors and Exceptions
- ValueError exception
- ZeroDivisionError exception
- try except clause in Python
- debugging