Difference between revisions of "Python"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '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 …')
 
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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 (http://spoken-tutorial.org/NMEICT-Intro).
+
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.   
 
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''': Science and Software Engineer Students
  
  
Line 120: Line 122:
  
 
* illustration of other plots, matplotlib help <br />
 
* illustration of other plots, matplotlib help <br />
 +
==Module 3: using Sage  ==
  
==Module 3: Handling Large Data Files  ==
+
===  Getting started with sage notebook ===
 +
 
 +
* about sage <br />
 +
** … <br />
 +
 
 +
* starting the notebook server <br />
 +
 
 +
* using the UI <br />
 +
** typesetting & print <br />
 +
** selecting language <br />
 +
*** sage <br />
 +
*** LaTeX <br />
 +
*** python <br />
 +
** help <br />
 +
*** sum(<tab> <br />
 +
*** ? <br />
 +
 
 +
=== Getting started with symbolics ===
 +
 
 +
* symbolic expressions <br />
 +
** built-in constants & functions <br />
 +
** algebraic expressions, <br />
 +
** series <br />
 +
** integration, differentiation <br />
 +
** matrices <br />
 +
 
 +
* symbolic functions <br />
 +
** defining <br />
 +
 
 +
* simplification <br />
 +
 
 +
* finding roots & factors <br />
 +
 
 +
* substituting expressions <br />
 +
 
 +
* output formats <br />
 +
 
 +
=== Using Sage ===
 +
 
 +
* ABCD <br />
 +
** Degree <br />
 +
*** RBT - U <br />
 +
 
 +
* Calculus <br />
 +
** limits <br />
 +
** differentiation <br />
 +
** integration <br />
 +
*** indefinite <br />
 +
*** definite <br />
 +
** piece-wise functions <br />
 +
** differential equations <br />
 +
** maxima, minima <br />
 +
 
 +
* Linear Algebra <br />
 +
** Vectors and Matrices <br />
 +
*** constructions <br />
 +
** Vector Operations <br />
 +
*** linear combination <br />
 +
*** dot <br />
 +
*** cross <br />
 +
*** pairwise <br />
 +
** Matrix Operations <br />
 +
*** linear combination <br />
 +
*** matrix multiplication <br />
 +
*** inverse <br />
 +
*** transpose <br />
 +
*** adjoint <br />
 +
*** rank <br />
 +
*** determinant <br />
 +
*** trace <br />
 +
*** norm <br />
 +
** Solving equations <br />
 +
** Eigenvalues, eigenvectors <br />
 +
 
 +
* Graph Theory <br />
 +
 
 +
* Number Theory <br />
 +
 
 +
=== Using sage to teach ===
 +
 
 +
* @interact <br />
 +
 
 +
* 2D, 3D graphics <br />
 +
 
 +
* Graph Theory <br />
 +
 
 +
* Share, Publish <br />
 +
 
 +
* print <br />
 +
==Module 4: Handling Large Data Files  ==
  
 
===  Getting started with lists ===
 
===  Getting started with lists ===
Line 200: Line 292:
  
 
* std <br />
 
* std <br />
 
+
==Module 5: Arrays and Matrices  ==
==Module 4: Arrays and Matrices  ==
+
  
 
=== Getting started with arrays ===
 
=== Getting started with arrays ===
Line 229: Line 320:
  
 
=== Matrices ===
 
=== Matrices ===
[[  /Matrices | (Scripts)  ]]
 
  
 
* creating matrices <br />
 
* creating matrices <br />
Line 252: Line 342:
  
 
* lstsq <br />
 
* lstsq <br />
 
==Module 5: using Sage  ==
 
 
===  Getting started with sage notebook ===
 
 
* about sage <br />
 
** … <br />
 
 
* starting the notebook server <br />
 
 
* using the UI <br />
 
** typesetting & print <br />
 
** selecting language <br />
 
*** sage <br />
 
*** LaTeX <br />
 
*** python <br />
 
** help <br />
 
*** sum(<tab> <br />
 
*** ? <br />
 
 
=== Getting started with symbolics ===
 
 
* symbolic expressions <br />
 
** built-in constants & functions <br />
 
** algebraic expressions, <br />
 
** series <br />
 
** integration, differentiation <br />
 
** matrices <br />
 
 
* symbolic functions <br />
 
** defining <br />
 
 
* simplification <br />
 
 
* finding roots & factors <br />
 
 
* substituting expressions <br />
 
 
* output formats <br />
 
 
=== Using Sage ===
 
 
* ABCD <br />
 
** Degree <br />
 
*** RBT - U <br />
 
 
* Calculus <br />
 
** limits <br />
 
** differentiation <br />
 
** integration <br />
 
*** indefinite <br />
 
*** definite <br />
 
** piece-wise functions <br />
 
** differential equations <br />
 
** maxima, minima <br />
 
 
* Linear Algebra <br />
 
** Vectors and Matrices <br />
 
*** constructions <br />
 
** Vector Operations <br />
 
*** linear combination <br />
 
*** dot <br />
 
*** cross <br />
 
*** pairwise <br />
 
** Matrix Operations <br />
 
*** linear combination <br />
 
*** matrix multiplication <br />
 
*** inverse <br />
 
*** transpose <br />
 
*** adjoint <br />
 
*** rank <br />
 
*** determinant <br />
 
*** trace <br />
 
*** norm <br />
 
** Solving equations <br />
 
** Eigenvalues, eigenvectors <br />
 
 
* Graph Theory <br />
 
 
* Number Theory <br />
 
 
=== Using sage to teach ===
 
 
* @interact <br />
 
 
* 2D, 3D graphics <br />
 
 
* Graph Theory <br />
 
 
* Share, Publish <br />
 
 
* print <br />
 
  
 
==Module 6: Python Language: Basics==
 
==Module 6: Python Language: Basics==
Line 375: Line 373:
 
*** slicing, striding <br />
 
*** slicing, striding <br />
  
=== I/O ===  
+
=== I/O ===
 +
Input Output in Python
  
 
=== Conditionals ===
 
=== Conditionals ===
Line 382: Line 381:
  
 
* pass <br />
 
* pass <br />
 
* <br />
 
  
 
===  Loops ===
 
===  Loops ===
[[  /Loops |(Scripts)  ]]
 
  
 
* while <br />
 
* while <br />
Line 453: Line 449:
  
 
=== Sets ===
 
=== Sets ===
 +
Sets
 +
 +
About sets in python
  
 
==Module 8: Python Language: Advanced==
 
==Module 8: Python Language: Advanced==
Line 490: Line 489:
  
 
=== Testing and debugging ===
 
=== Testing and debugging ===
 +
Testing and debugging

Latest revision as of 12:23, 6 May 2019

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: Science and Software Engineer 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

  • invoking ipython
    if there's a problem, pre-requisites are not met.
  • getting out
  • explain the prompt
  • typing commands
    • 1+2
      • careful wording to differentiate from print
    • print 1+2
    • history (up, down arrows)
    • backspace, delete key
    • tab completion
      • ab
      • a
      • rou
      • ro
      • r
  • abs?, round?
  • handling typing errors
    • round(2.48,
      • close it
      • use C

Using the plot command interactively

  • ipython -pylab
    • pylab brings in the libraries necessary for Scientific Computing.
  • linspace,
  • len
  • clf
  • plot
  • using the plot ui

Embellishing a plot

  • Title
  • Label
  • line width, color, style
  • annotations

Saving plots

  • basic savefig
  • png, pdf, ps, eps, svg
  • going to OS and looking at the file

Multiple plots

  • overlays
    • linspace
      • give one with very few points, more points
      • show smoothness of the curve
  • legend
  • figure 1, figure2
  • subplots

Additional features of IPython

  • %save, %history, %run

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
  • pie chart
  • bar chart
  • log
  • illustration of other plots, matplotlib help

Module 3: using Sage

Getting started with sage notebook

  • about sage

  • starting the notebook server
  • using the UI
    • typesetting & print
    • selecting language
      • sage
      • LaTeX
      • python
    • help
      • sum(<tab>
      •  ?

Getting started with symbolics

  • symbolic expressions
    • built-in constants & functions
    • algebraic expressions,
    • series
    • integration, differentiation
    • matrices
  • symbolic functions
    • defining
  • simplification
  • finding roots & factors
  • substituting expressions
  • output formats

Using Sage

  • ABCD
    • Degree
      • RBT - U
  • Calculus
    • limits
    • differentiation
    • integration
      • indefinite
      • definite
    • piece-wise functions
    • differential equations
    • maxima, minima
  • Linear Algebra
    • Vectors and Matrices
      • constructions
    • Vector Operations
      • linear combination
      • dot
      • cross
      • pairwise
    • Matrix Operations
      • linear combination
      • matrix multiplication
      • inverse
      • transpose
      • adjoint
      • rank
      • determinant
      • trace
      • norm
    • Solving equations
    • Eigenvalues, eigenvectors
  • Graph Theory
  • Number Theory

Using sage to teach

  • @interact
  • 2D, 3D graphics
  • Graph Theory
  • Share, Publish
  • print

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

Contributors and Content Editors

Gaurav, Minal, Nancyvarkey, PoojaMoolya