Difference between revisions of "Python 3.4.3"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Subplots)
(Additional features of IPython)
Line 88: Line 88:
 
=== Additional features of IPython ===
 
=== Additional features of IPython ===
  
* <code>%save</code>, <code>%history</code>, <code>%run</code><br />
+
#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  ==
 
==Module 2: Plotting Experimental Data  ==

Revision as of 16:00, 9 October 2020

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

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

  1. Use Python 3.5.2
  2. Use Ipython version 5.1.0
  3. IPython is an enhanced interactive Python interpreter.
  4. Invoke the IPython interpreter
  5. Quit the IPython interpreter
  6. Navigate the IPython session history
  7. Use tab-completion to work faster.
  8. See the documentation of functions using question mark.
  9. Interrupt commands using Ctrl + C when we make an error.
  10. round command

Using the plot command interactively

  1. Use Python 3.4.3
  2. Use Ipython version 5.1.0
  3. Start IPython with pylab.
  4. ImportError if matplotlib is not installed
  5. clf() function
  6. Use the linspace function to create equally spaced points in a region.
  7. Find the length of sequences using len function.
  8. Plot mathematical functions using plot.
  9. Clear drawing area using clf.
  10. Usage of buttons in the UI of the plot window such as - save, zoom, move axis, back and forward and Home

Embellishing a plot

  1. Use Python 3.4.3
  2. Use Ipython version 5.1.0
  3. Modify the attributes of a plot
  4. Pass additional keyword arguments to plot command
  5. Add title to a plot using 'title' command.
  6. Incorporate LaTeX style formatting by adding a $ sign before and after the string.
  7. Label x and y axes using xlabel() and ylabel() commands.
  8. Add annotations to a plot using annotate() command.
  9. Get the limits of axes using xlim() and ylim() commands.
  10. Set the limits of axes using xlim() and ylim() commands.

Saving plots

  1. Use Python 3.4.3
  2. Use Ipython version 5.1.0
  3. Save plots using the savefig() function.
  4. Save the plots in different formats like
    • pdf
    • ps
    • png
    • svg
    • eps

Multiple plots

  1. Use Python 3.4.3
  2. Use IPython 5.1.0
  3. Draw multiple plots which are overlaid.
  4. Operations on individual plots.
  5. Use the figure command.
  6. Distinguish between multiple overlaid plots.
  7. Use the legend command.
  8. Serial number of the plot to select corresponding plot.
  9. Switch between the plots
  10. Saving individual plots.

Subplots

  1. Use Python 3.4.3
  2. Use IPython 5.1.0
  3. Creating subplots
  4. Switching between subplots.
  5. Subplot command
  6. Passing arguments to subplot command.
  7. First argument is the number of rows of subplots.
  8. Second argument is the number of columns of subplots
  9. Third argument specifies the serial number for subplot.

Additional features of IPython

  1. Use Python 3.4.3
  2. Use IPython 5.1.0
  3. Retrieve the history using  %history command.
  4. View only a part of history by passing argument to %history command.
  5. Pass arguments to %history to get particular lines of code
  6. Save the required lines of code in required order using '%save' command.
  7. Use '%run -i' command to run a saved script.

Module 2: Plotting Experimental Data

loading data from files

  • loadtxt with unpack=True
    • primes.list (one col)
    • pendulum.txt (two col)

Plotting the data

  • plot L vs. T2
    • using square function
  • problem with 3 cols
    • 3rd column is error
    • error bar

Other types of plots

  • scatter
  • log-log plots

Plotting charts

  • pie chart
  • bar chart
  • illustration of other plots, matplotlib help

Module 4: Handling Large Data Files

Getting started with lists

  • empty
  • filled lists
    • heterogenity
  • accessing
  • len
  • append elements
  • del (+ remove)

Getting started with for

  • blocks in python
    • (indentation)
  • blocks in ipython
    • … prompt
    • hitting enter
  • for with a list
  • range function

Getting started with strings

  • strings
    • single, double, triple quoted
  • accessing elements
  • show immutability
  • tell that there are methods for manipulation

Getting started with files

  • show file object
  • read the file with read
  • closing the file
  • for line in file:
  • print a line
  • append the lines to a list

Parsing data

  • explain what is parsing
  • strip (with strings)
  • split (with strings)
    • with delimiters
      • specify space as delimiter
  • datatype conversion
  • reading from files
    • do the same problem done with loadtxt (for pendulum)
    • basic parse sslc text

Statistics

  • mean
    • summing
  • median
  • std

Module 5: Arrays and Matrices

Getting started with arrays

  • why arrays
    • speed - simply say
    • array level operations
  • creating arrays
    • direct data
    • list conversion
    • homogeneous
    • builtins - identitiy, zeros,
  • 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,
  • matrix operations
    • + - * /
    • dot
    • inv
    • det
    • eig
    • norm
    • svd

Least square fit

  • show pendulum
    • use loadtxt
  • lstsq

Module 6: Python Language: Basics

Basic datatypes & operators

  • int
    • L, long
  • float
    • repr, str
  • complex
  • boolean
  • conversion functions
  • sequence datatypes & mutability
    • list available sequence datatypes
      • string
      • list
      • tuple
    • mutability
    • conversion
    • common stuff
      • len
      • in
      • max, min, sum, sorted, reversed
      • accessing individual elements
      • slicing, striding

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
  • 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

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat, PoojaMoolya, Trupti