Prep

  1. Open Spyder - source activate spyder
  2. Clear workbooks
  3. Close workbooks
  4. Enter full screen mode (Chrome = F11)
  5. Chrome zoom 75% seems to work ok (ctrl-+ or ctrl--)

File Version

Get all files at Github - https://github.com/Tooblippe/python_introduction

Version Comment
2 *Current Presented 3 July 2015, Updated Matlab slide, Added where to find information slides
1 Presented 1 June 2015, Original presentation
In [ ]:
from IPython.html.services.config import ConfigManager
from IPython.utils.path import locate_profile
cm = ConfigManager(profile_dir=locate_profile(get_ipython().profile))
cm.update('livereveal', {
              'theme': 'simple',
              'transition': 'fade',
              'start_slideshow_at': 'selected',
              'width': 900,
              'height': 900
         
})


#thems  -Black (default) - White - League - Sky - Beige - Simple, Serif - Blood - Night - Moon - Solarized
#transitions - None - Fade - Slide - Convex - Concave - Zoom

%pylab inline

# --- end of setup

# ... actual presentation starts below

Contents [1]

guido

  • Introduction to Python
  • Who uses Python?
  • Python implementations
  • Where does it run?
  • Python 2 vs. 3
  • Batteries included philosophy
  • Language basics - demo
  • Python compared to Matlab
  • Python weaknesses

Contents [2]

guido

  • Python distributions
  • The Python eco-system you will use
  • Python IDE's
  • Python GUI development
  • Scientific Python building blocks - demo
  • Plotting - demo
  • Machine learning -demo
  • Control systems
  • Simulation

Contents [3]

guido

  • Signal processing - demo
  • Optimising code
  • Multi-processing
  • Embedded systems
  • Python and Excel/PPT/Word
  • Packaging your code / app

About me

  • Electrical Engineer guido
  • Currently busy with M.Eng
  • Principal Consultant at Eon Consulting

  • Use Windows, Ubuntu GNU/Linux and Mac

  • People at work use Excel (alot) [big time]
  • Hobby with Python, Arduino, Energy Loggers, RaspberryPi
  • Python training classes to grownups and kids
  • Speaker at PyCon

What is Python?

  • Python is an interpreted, object-oriented, high-level programming language
  • High-level built in data structures guido
  • Dynamic typing
  • Attractive for Rapid Application Development
  • Use as a scripting or glue language to connect existing components together guido
  • Immense growth in the data/science environment
  • Large standard library (Batteries Included)
  • Been around for 25 years
  • Free and Open Source

Who uses Python? [1]

Who uses Python? [2]

Python variants and implementations

Python runs on many platforms and sofware stacks

Implementation Platform
CPython - reference C++ guido
PyPy (JIT, Stackless,Faster) C ++ guido
IronPython .NET CLR guido
jython (JIT) Java guido
MicroPython (Embedded) ARM guido

Python runs on most hardware platforms

Platform Platform
GNU/Linux guido Windows guido
Macintosh guido IOS guido
Android guido Microprocessors guido
RaspberryPi guido and.. something in your house

Compiled vs. Interpreted

guido

Applications:

  • Web and Internet development
  • Data analysis
  • Numerical processing
  • Video and audio editing (ILM)
  • Web scraping
  • Science
  • Desktop applications
  • Software Development
  • Operating systems
  • System administration
  • ( ... )

Standard library

  • Batteries included guido
  • Almost everything you need is included
  • os- Working with the operating system
  • httplib- Grabbing web pages
  • email - Sending email
  • glob - Using glob for filename wildcards
  • math and random
  • unittest- Unit testing framework
  • timeit- Measure execution time of small code snippets
  • datetime - Working with dates and times
  • zipfile, tarfile
  • ( ... many, many more ..) Complete Library
  • Great website - Python Module of the Week

Python basics

print "A short introduction"

Python Basics Workbook

Python Basics Workbook (2)

Python 2 vs. Python 3

  • Best to move to Python 3 when you start guido

Python compared to Matlab

guido

Image Credit - Nelis Willers

Some disadvantages of Matlab

Not much, its awesome guido

  • The algorithms are proprietary
  • Expensive
  • Frequent release cycles
  • It makes portability more difficult
  • Difficult for 3rd parties to extend or create tools for Matlab

Advantages of Matlab

  • It has a solid (and tested) amount of functions
  • Simulink is a product which is simply not available elsewhere
  • It has a large scientific community; it is used on many universities (but few companies have the money to buy a license)

Advantages of Python

  • Free
  • You can use it everywhere (almost)
  • Namespaces
  • Introspection
  • Portability
  • You can run Matlab in the IPython Notebook
  • Basically IPython changed the game for most people

Disadvanges of Python

  • Sometimes conceived to be slow, but we will investigate this further

  • Hobyists != Good programmers (MOSTLY)

Python distributions

  • Installing some modules require compilation (c++, Fortran)
  • Can create frustration to install dependencies
  • Download and install a free distribution like   * Anaconda guido   * Enthought
  • 270+ packages guido
  • No modification to system path
  • Have taught Python - Linux, Mac, Windows without any problems
  • Package management and Environments
  • more distributions here

The Python interactive ecosystem

  • Python, IPython, Notebook guido
  • Python is the main interpreter
  • Improved interpreters exist e.g. IPython
  • IPython also bundles the notebook we are using now
  • IPython interactive computing
  • IPython Demo (terminal, QTConsole)
  • Notebook Basics Demo

Python IDE's

  • Integrated Development Environments - a personal choice guido
  • Many options exists
  • After countless hours of searching and trying I recommend:

Free

Commercial

  • PyCharm (has community edition for free)

Python GUI development (1)

  • Tkinter comes with Python std lib
  • I found GUI development to be non trivial

  • Pyside, PyQt - binding of the cross-platform GUI toolkit Qt

  • Kivy (<-- Recomend you spend time here)

    • innovative user interfaces, such as multi-touch apps.
    • runs on Linux, Windows, Mac, Android and iOS
    • could not get IOS working

guido guido

Python GUI development (2)

Mayavi for scientific apps

guido

Python GUI development (3)

TK example - Tetris

(source - http://code.google.com/p/tetris-tk)

In [1]:
#!/usr/bin/env python
"""
Tetris Tk - A tetris clone written in Python using the Tkinter GUI library.

Controls:
    Left Arrow      Move left
    Right Arrow     Move right
    Down Arrow      Move down
    Up Arrow        Drop Tetronimoe to the bottom
    'a'             Rotate anti-clockwise (to the left)
    'b'             Rotate clockwise (to the right)
    'p'             Pause the game.
"""

from Tkinter import *
from time import sleep
from random import randint
import tkMessageBox
import sys

SCALE = 20
OFFSET = 3
MAXX = 10
MAXY = 22

NO_OF_LEVELS = 10

LEFT = "left"
RIGHT = "right"
DOWN = "down"

direction_d = { "left": (-1, 0), "right": (1, 0), "down": (0, 1) }

def level_thresholds( first_level, no_of_levels ):
    """
    Calculates the score at which the level will change, for n levels.
    """
    thresholds =[]
    for x in xrange( no_of_levels ):
        multiplier = 2**x
        thresholds.append( first_level * multiplier )
    
    return thresholds

class status_bar( Frame ):
    """
    Status bar to display the score and level
    """
    def __init__(self, parent):
        Frame.__init__( self, parent )
        self.label = Label( self, bd=1, relief=SUNKEN, anchor=W )
        self.label.pack( fill=X )
        
    def set( self, format, *args):
        self.label.config( text = format % args)
        self.label.update_idletasks()
        
    def clear( self ):
        self.label.config(test="")
        self.label.update_idletasks()

class Board( Frame ):
    """
    The board represents the tetris playing area. A grid of x by y blocks.
    """
    def __init__(self, parent, scale=20, max_x=10, max_y=20, offset=3):
        """
        Init and config the tetris board, default configuration:
        Scale (block size in pixels) = 20
        max X (in blocks) = 10
        max Y (in blocks) = 20
        offset (in pixels) = 3
        """
        Frame.__init__(self, parent)
        
        # blocks are indexed by there corrdinates e.g. (4,5), these are
        self.landed = {}
        self.parent = parent
        self.scale = scale
        self.max_x = max_x
        self.max_y = max_y
        self.offset = offset        

        self.canvas = Canvas(parent,
                             height=(max_y * scale)+offset,
                             width= (max_x * scale)+offset)
        self.canvas.pack()

    def check_for_complete_row( self, blocks ):
        """
        Look for a complete row of blocks, from the bottom up until the top row
        or until an empty row is reached.
        """
        rows_deleted = 0
        
        # Add the blocks to those in the grid that have already 'landed'
        for block in blocks:
            self.landed[ block.coord() ] = block.id
        
        empty_row = 0

        # find the first empty row
        for y in xrange(self.max_y -1, -1, -1):
            row_is_empty = True
            for x in xrange(self.max_x):
                if self.landed.get((x,y), None):
                    row_is_empty = False
                    break;
            if row_is_empty:
                empty_row = y
                break

        # Now scan up and until a complete row is found. 
        y = self.max_y - 1
        while y > empty_row:
 
            complete_row = True
            for x in xrange(self.max_x):
                if self.landed.get((x,y), None) is None:
                    complete_row = False
                    break;

            if complete_row:
                rows_deleted += 1
                
                #delete the completed row
                for x in xrange(self.max_x):
                    block = self.landed.pop((x,y))
                    self.delete_block(block)
                    del block

                    
                # move all the rows above it down
                for ay in xrange(y-1, empty_row, -1):
                    for x in xrange(self.max_x):
                        block = self.landed.get((x,ay), None)
                        if block:
                            block = self.landed.pop((x,ay))
                            dx,dy = direction_d[DOWN]
                            
                            self.move_block(block, direction_d[DOWN])
                            self.landed[(x+dx, ay+dy)] = block

                # move the empty row down index down too
                empty_row +=1
                # y stays same as row above has moved down.
                
            else:
                y -= 1
                
        #self.output() # non-gui diagnostic
        
        # return the score, calculated by the number of rows deleted.        
        return (100 * rows_deleted) * rows_deleted
                
    def output( self ):
        for y in xrange(self.max_y):
            line = []
            for x in xrange(self.max_x):
                if self.landed.get((x,y), None):
                    line.append("X")
                else:
                    line.append(".")
            print "".join(line)
            
    def add_block( self, (x, y), colour):
        """
        Create a block by drawing it on the canvas, return
        it's ID to the caller.
        """
        rx = (x * self.scale) + self.offset
        ry = (y * self.scale) + self.offset
        
        return self.canvas.create_rectangle(
            rx, ry, rx+self.scale, ry+self.scale, fill=colour
        )
        
    def move_block( self, id, coord):
        """
        Move the block, identified by 'id', by x and y. Note this is a
        relative movement, e.g. move 10, 10 means move 10 pixels right and
        10 pixels down NOT move to position 10,10. 
        """
        x, y = coord
        self.canvas.move(id, x*self.scale, y*self.scale)
        
    def delete_block(self, id):
        """
        Delete the identified block
        """
        self.canvas.delete( id )
        
    def check_block( self, (x, y) ):
        """
        Check if the x, y coordinate can have a block placed there.
        That is; if there is a 'landed' block there or it is outside the
        board boundary, then return False, otherwise return true.
        """
        if x < 0 or x >= self.max_x or y < 0 or y >= self.max_y:
            return False
        elif self.landed.has_key( (x, y) ):
            return False
        else:
            return True

class Block(object):
    def __init__( self, id, (x, y)):
        self.id = id
        self.x = x
        self.y = y
        
    def coord( self ):
        return (self.x, self.y)
        
class shape(object):
    """
    Shape is the  Base class for the game pieces e.g. square, T, S, Z, L,
    reverse L and I. Shapes are constructed of blocks. 
    """
    @classmethod        
    def check_and_create(cls, board, coords, colour ):
        """
        Check if the blocks that make the shape can be placed in empty coords
        before creating and returning the shape instance. Otherwise, return
        None.
        """
        for coord in coords:
            if not board.check_block( coord ):
                return None
        
        return cls( board, coords, colour)
            
    def __init__(self, board, coords, colour ):
        """
        Initialise the shape base.
        """
        self.board = board
        self.blocks = []
        
        for coord in coords:
            block = Block(self.board.add_block( coord, colour), coord)
            
            self.blocks.append( block )
            
    def move( self, direction ):
        """
        Move the blocks in the direction indicated by adding (dx, dy) to the
        current block coordinates
        """
        d_x, d_y = direction_d[direction]
        
        for block in self.blocks:

            x = block.x + d_x
            y = block.y + d_y
            
            if not self.board.check_block( (x, y) ):
                return False
            
        for block in self.blocks:
            
            x = block.x + d_x
            y = block.y + d_y
            
            self.board.move_block( block.id, (d_x, d_y) )
            
            block.x = x
            block.y = y
        
        return True
            
    def rotate(self, clockwise = True):
        """
        Rotate the blocks around the 'middle' block, 90-degrees. The
        middle block is always the index 0 block in the list of blocks
        that make up a shape.
        """
        # TO DO: Refactor for DRY
        middle = self.blocks[0]
        rel = []
        for block in self.blocks:
            rel.append( (block.x-middle.x, block.y-middle.y ) )
            
        # to rotate 90-degrees (x,y) = (-y, x)
        # First check that the there are no collisions or out of bounds moves.
        for idx in xrange(len(self.blocks)):
            rel_x, rel_y = rel[idx]
            if clockwise:
                x = middle.x+rel_y
                y = middle.y-rel_x
            else:
                x = middle.x-rel_y
                y = middle.y+rel_x
            
            if not self.board.check_block( (x, y) ):
                return False
            
        for idx in xrange(len(self.blocks)):
            rel_x, rel_y = rel[idx]
            if clockwise:
                x = middle.x+rel_y
                y = middle.y-rel_x
            else:
                x = middle.x-rel_y
                y = middle.y+rel_x
            
            
            diff_x = x - self.blocks[idx].x 
            diff_y = y - self.blocks[idx].y 
            
            self.board.move_block( self.blocks[idx].id, (diff_x, diff_y) )
            
            self.blocks[idx].x = x
            self.blocks[idx].y = y
       
        return True
    
class shape_limited_rotate( shape ):
    """
    This is a base class for the shapes like the S, Z and I that don't fully
    rotate (which would result in the shape moving *up* one block on a 180).
    Instead they toggle between 90 degrees clockwise and then back 90 degrees
    anti-clockwise.
    """
    def __init__( self, board, coords, colour ):
        self.clockwise = True
        super(shape_limited_rotate, self).__init__(board, coords, colour)
    
    def rotate(self, clockwise=True):
        """
        Clockwise, is used to indicate if the shape should rotate clockwise
        or back again anti-clockwise. It is toggled.
        """
        super(shape_limited_rotate, self).rotate(clockwise=self.clockwise)
        if self.clockwise:
            self.clockwise=False
        else:
            self.clockwise=True
        

class square_shape( shape ):
    @classmethod
    def check_and_create( cls, board ):
        coords = [(4,0),(5,0),(4,1),(5,1)]
        return super(square_shape, cls).check_and_create(board, coords, "red")
        
    def rotate(self, clockwise=True):
        """
        Override the rotate method for the square shape to do exactly nothing!
        """
        pass
        
class t_shape( shape ):
    @classmethod
    def check_and_create( cls, board ):
        coords = [(4,0),(3,0),(5,0),(4,1)]
        return super(t_shape, cls).check_and_create(board, coords, "yellow" )
        
class l_shape( shape ):
    @classmethod
    def check_and_create( cls, board ):
        coords = [(4,0),(3,0),(5,0),(3,1)]
        return super(l_shape, cls).check_and_create(board, coords, "orange")
    
class reverse_l_shape( shape ):
    @classmethod
    def check_and_create( cls, board ):
        coords = [(5,0),(4,0),(6,0),(6,1)]
        return super(reverse_l_shape, cls).check_and_create(
            board, coords, "green")
        
class z_shape( shape_limited_rotate ):
    @classmethod
    def check_and_create( cls, board ):
        coords =[(5,0),(4,0),(5,1),(6,1)]
        return super(z_shape, cls).check_and_create(board, coords, "purple")
        
class s_shape( shape_limited_rotate ):
    @classmethod
    def check_and_create( cls, board ):
        coords =[(5,1),(4,1),(5,0),(6,0)]
        return super(s_shape, cls).check_and_create(board, coords, "magenta")
        
class i_shape( shape_limited_rotate ):
    @classmethod
    def check_and_create( cls, board ):
        coords =[(4,0),(3,0),(5,0),(6,0)]
        return super(i_shape, cls).check_and_create(board, coords, "blue")
        
class game_controller(object):
    """
    Main game loop and receives GUI callback events for keypresses etc...
    """
    def __init__(self, parent):
        """
        Intialise the game...
        """
        self.parent = parent
        self.score = 0
        self.level = 0
        self.delay = 1000    #ms
        
        #lookup table
        self.shapes = [square_shape,
                      t_shape,
                      l_shape,
                      reverse_l_shape,
                      z_shape,
                      s_shape,
                      i_shape ]
        
        self.thresholds = level_thresholds( 500, NO_OF_LEVELS )
        
        self.status_bar = status_bar( parent )
        self.status_bar.pack(side=TOP,fill=X)
        #print "Status bar width",self.status_bar.cget("width")

        self.status_bar.set("Score: %-7d\t Level: %d " % (
            self.score, self.level+1)
        )
        
        self.board = Board(
            parent,
            scale=SCALE,
            max_x=MAXX,
            max_y=MAXY,
            offset=OFFSET
            )
        
        self.board.pack(side=BOTTOM)
        
        self.parent.bind("<Left>", self.left_callback)
        self.parent.bind("<Right>", self.right_callback)
        self.parent.bind("<Up>", self.up_callback)
        self.parent.bind("<Down>", self.down_callback)
        self.parent.bind("a", self.a_callback)
        self.parent.bind("s", self.s_callback)
        self.parent.bind("p", self.p_callback)
        
        self.shape = self.get_next_shape()
        #self.board.output()

        self.after_id = self.parent.after( self.delay, self.move_my_shape )
        
    def handle_move(self, direction):
        #if you can't move then you've hit something
        if not self.shape.move( direction ):
            
            # if your heading down then the shape has 'landed'
            if direction == DOWN:
                self.score += self.board.check_for_complete_row(
                    self.shape.blocks
                    )
                del self.shape
                self.shape = self.get_next_shape()
                
                # If the shape returned is None, then this indicates that
                # that the check before creating it failed and the
                # game is over!
                if self.shape is None:
                    tkMessageBox.showwarning(
                        title="GAME OVER",
                        message ="Score: %7d\tLevel: %d\t" % (
                            self.score, self.level),
                        parent=self.parent
                        )
                    Toplevel().destroy()
                    self.parent.destroy()
                    sys.exit(0)
                
                # do we go up a level?
                if (self.level < NO_OF_LEVELS and 
                    self.score >= self.thresholds[ self.level]):
                    self.level+=1
                    self.delay-=100
                    
                self.status_bar.set("Score: %-7d\t Level: %d " % (
                    self.score, self.level+1)
                )
                
                # Signal that the shape has 'landed'
                return False
        return True

    def left_callback( self, event ):
        if self.shape:
            self.handle_move( LEFT )
        
    def right_callback( self, event ):
        if self.shape:
            self.handle_move( RIGHT )

    def up_callback( self, event ):
        if self.shape:
            # drop the tetrominoe to the bottom
            while self.handle_move( DOWN ):
                pass

    def down_callback( self, event ):
        if self.shape:
            self.handle_move( DOWN )
            
    def a_callback( self, event):
        if self.shape:
            self.shape.rotate(clockwise=True)
            
    def s_callback( self, event):
        if self.shape:
            self.shape.rotate(clockwise=False)
        
    def p_callback(self, event):
        self.parent.after_cancel( self.after_id )
        tkMessageBox.askquestion(
            title = "Paused!",
            message="Continue?",
            type=tkMessageBox.OK)
        self.after_id = self.parent.after( self.delay, self.move_my_shape )
    
    def move_my_shape( self ):
        if self.shape:
            self.handle_move( DOWN )
            self.after_id = self.parent.after( self.delay, self.move_my_shape )
        
    def get_next_shape( self ):
        """
        Randomly select which tetrominoe will be used next.
        """
        the_shape = self.shapes[ randint(0,len(self.shapes)-1) ]
        return the_shape.check_and_create(self.board)
        
        
if __name__ == "__main__":
    root = Tk()
    root.title("Tetris Tk")
    theGame = game_controller( root )
    
    root.mainloop()

Scientific building blocks

guido guido guido guido

Numpy guido

  • NumPy is the fundamental package for scientific computing with Python
  • a powerful N-dimensional array object (Matrix)
  • tools for integrating C/C++ and Fortran code
  • useful linear algebra, Fourier transform, and random number capabilities

  • Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data.

  • Arbitrary data-types can be defined.

NumPy Demo

Plotting

Many rich plotting options exist

  • Matplotlib
  • Bokeh
  • mpld3
  • ggplot (ported from R)

Example Notebook - Matplotlib

Example Notebook - Bokeh

Example Notebook - mpld3

IPython Notebook Widgets

The IPython Notebook also have functionality for interactive components:

Pandas guido

pandas is provides high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

  • analog to R - data.frame
  • tabular and time series data
  • think excel

pandas demo

Sympy guido

  • SymPy is a Python library for symbolic mathematics.
  • It aims to become a full-featured computer algebra system (CAS)
  • SymPy is written entirely in Python and does not require any external libraries.

SymPy Demo

Statsmodels guido

  • Linear regression models
  • Generalized linear models
  • Discrete choice models
  • Robust linear models
  • Many models and functions for time series analysis
  • Nonparametric estimators
  • A wide range of statistical tests
  • Plotting functions

Ordinary Least Squares Demo

Machine learning

  • Pattern Recognition guido
  • key module - scikit-learn

  • Simple and efficient tools for data mining and data analysis

  • Accessible to everybody, and reusable in various contexts
  • Built on NumPy, SciPy, and matplotlib

  • Classification, Regression

  • Clustering, Model selection
  • Dimensionality reduction ### Face Recognition Demo

Control systems [1] guido

The python-control package is a set of python classes and functions that implement common operations for the analysis and design of feedback control systems.

  • Linear input/output systems in state space and frequency domain (transfer functions)
  • Block diagram algebra: serial, parallel and feedback interconnections
  • Time response: initial, step, impulse (using the scipy.signal package)
  • Frequency response: Bode and Nyquist plots
  • Control analysis: stability, reachability, observability, stability margins
  • Estimator design: linear quadratic estimator (Kalman filter)
  • Download package

Control systems [2]

guido guido guido guido guido guido guido guido

Simulation

  • No real alternative to Simulink

guido

A snake with Denel origins - Pyradi pyradi

The pyradi toolkit is a Python toolkit with worked examples to perform optical and infrared computational radiometry (flux flow) calculations.

pyradi

  • Models of physical radiators (e.g., Planck's Law) and conversion between values expressed in different units.

  • Mathematical operations (e.g., spectral integrals, spatial integrals, spectral convolution)

  • Data manipulation (e.g., file input/output, interpolation, spectral quantity conversions, reading Flir Inc PTW files)

  • Detector modelling from physical parameters, detection range and probability of detection calculation.

  • 3-D noise analysis of image sequences

  • Modtran tape7 read functions

  • Graphical visualization in compact format, including cartesian, polar, image and mesh plots.

Used by Denel, CSIR, Airbus and two or three labs overseas.

Python use with RF Engineering

smith_chart.png scikit-rf (aka skrf) is an Open Source, BSD-licensed package for RF/Microwave engineering implemented in the Python programming language. Based on this Paper from MIT

  • Read/Write touchstone (.s2p, s?p) files

  • Basic algebraic operations on networks’ scattering parameters

  • Cascade/De-embed 2-port networks pyradi

  • Connect n-port networks

  • Plot network parameter data [s, y, z] in ( dB, Phase, Smith chart, ...)

  • Save plots in vector format for publication (a feature of matplotlib)

  • 1-port calibration:

    • SOL
    • Least Squares (any number of standards)
    • SDDL
  • 2-port calibration:

    • SOLT
    • Unknown Thru
    • General 8-term
    • TRL ( partial support only) Enhanced Response
  • Inegrated VNA virtual instruments (completeness varies by model)

    • PNA, PNAX
    • ZVA
    • HP8510, HP8720
  • Circuit synthesis

  • Transmission line models

Databases guido

  • interact directly with sqlite, mySQL, Oracle, MSSql etc
  • Chinook database guido
In [ ]:
import pandas as pd
from sqlalchemy import create_engine 

disk_engine = create_engine('sqlite:///resources/data/Chinook_Sqlite.sqlite') 
df1 = pd.read_sql( 'select * from Album limit 10', disk_engine)
df1
In [ ]:
df2 = pd.read_sql( 'select * from Employee', disk_engine)
df2

Optimising code [1] guido

Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex). It makes writing C extensions for Python as easy as Python itself. Cython gives you the combined power of Python and C to let you: guido

Optimising code [2] guido

  • Cython is the missing link between the simplicity of Python and the speed of C / C++ / Fortran
  • tune Python code into plain C performance by adding static type declarations

You write Python code:

  1. Cython translates it into C code
  2. your C compiler builds a shared library for CPython
  3. you import your module into CPython

Multi-processing

  • Built in multiprocessing library
  • IPython provides more options
  • NVIDIA CUDA - parallel computation API from Python
  • Apache Spark - is a fast and general engine for large-scale data processing.
  • Apache hadoop - reliable, scalable, distributed computing

guido guido guido

Embedded systems[1] guido

RaspberryPi

  • Credit-card sized computer
  • Runs Ubuntu, Debian, Windows 10 IOT
  • Base language is Python
  • Used in thousands of hobby and science applications
  • Also has Mathematica and Wolfram Engine built in for educational purposes

Embedded systems[2] guido

MicroPython

  • MicroPython is P3 that runs on a microcontroller.
  • Low-level Python operating system on chip
  • LED, GPIO, Servo Control, Interupts
  • Timers, PWM, DAC, ADC, UART, SPI, I2C

Servo Control Example Code

from pyb import Servo
    s1 = Servo(1) 
    s1.angle(45) 
    s1.angle(-60, 1500) 
    s1.speed(50)

guido

Python and Excel/PPT/Word


Excel

  • Pandas saves to excel natively
  • XLWINGS - VBA replacement
  • pyXLL (commercial


PPT

Word

guido guido guido guido

Packaging your application

  • PyInstaller is a program that converts (packages) Python programs into stand-alone executables:
    • Windows,
    • Linux,
    • Mac
    • OS X,
    • Solaris
  • Bundle to one file or directory based install

3 Steps to get started

  1. Download Anaconda for your platform here - http://continuum.io/
  2. Start the oficial Python Tutorial https://docs.python.org/2/tutorial/
  3. Look at this list of cool resources - https://python.zeef.com/alan.richmond

Find this presentation here

.

http://bit.ly/denel_python

or scan

guido

References

Exported from Evernote

  1. Why are there no python RAD type IDE GUIs?

  2. PyCharm

  3. Python-control/Example: Vertical takeoff and landing aircraft - MurrayWiki

  4. Control Systems Library for Python - MurrayWiki

  5. logos

  6. Optimizing Python - A Case Study

  7. jython python implementation

  8. Wakari - Web-based Python Data Analysis

  9. Jupyter online jupyter

  10. Trinket helps you teach with code

  11. Anaconda Scientific Python Distribution

  12. Python vs Matlab - Python for scientists

  13. Python for scientists

  14. python powerpoint

  15. Spyder

  16. Overview — PySide 1.2.1 documentation

  17. Python Graphing Library | Documentation and Examples | plotly

  18. MicroPython - Python for microcontrollers python implementation

  19. MicroPython - Python for microcontrollers

  20. Why Python is Better than Matlab for Scientific Software | Meta Rabbit

  21. Introcution to Python : Outline

  22. pyinstaller/pyinstaller

  23. NelisW/PythonNotesToSelf

  24. NelisW/pyradi python science denel spesific

  25. scientific-python-lectures

  26. jrjohansson/scientific-python-lectures

  27. pyvim

  28. IPYTHON Notebooks by IPython

  29. IPython kernels for other languages · ipython/ipython Wiki

  30. A gallery of interesting IPython Notebooks · ipython/ipython Wiki

  31. RISE notebook presentation mode

  32. Skulpt Notebook Kernel

  33. Calysto/matlab_kernel

  34. notebook examples

  35. Example ipynb to test LIVE reveal extension.

  36. ide Enthought Canopy

  37. Enthought Scientific Computing Solutions

  38. pyton standard library

  39. Jake VanderPlas - notebooks

  40. Automate the Boring Stuff with Python | Practical Programming for Total Beginners book free

  41. Zoof — the interactive IDE for dynamic languages

  42. xlwings - Replace Excel VBA with Python!

  43. SQLAlchemy - The Database Toolkit for Python

  44. Python for Computational Science

  45. python vs matlab chapter 10, p91

  46. Python for Science and Engineering: a presentation to A*STAR and the …

  47. migrating-from-matlab-to-python. remember quda

  48. Python. Client side.

  49. SciPy.org — SciPy.org

  50. Python vs Matlab — Pyzo - Python to the people

  51. Camelot

  52. DENEL TALK FRAMEWORK

  53. NumPy — Numpy

  54. Natural Language Toolkit — NLTK 3.0 documentation

  55. IPython lecture notes Strang Linear Algebra

  56. Automate the export of PowerPoint files to Images | PowerPoint Presentation

  57. Introduction to Python for Statistical Learning | DataRobot

  58. potential course outline

  59. Astropy

  60. StatsModels: Statistics in Python — statsmodels documentation

  61. Trim whitespace using PIL - Stack Overflow

  62. scikit-learn: machine learning in Python — scikit-learn 0.16.1 documentation

  63. scikit-image: Image processing in Python — scikit-image

  64. Writing Python Compiled Modules - InfoSec Institute

  65. Vectorization – Magic for your Computations

  66. Online Python Tutor - Visualize Python, Java, JavaScript, and TypeScript code

  67. PyInstaller

  68. PyPy - Python implementation

  69. PyDev

  70. Pandas

  71. Python For Scientific Engineering - OpenOpt

  72. Publishing Workflows for IPython/Jupyter Notebooks

  73. Introduction — pyradi documentation denel spesific

  74. Notebook widgets

  75. Widgets in IPython notebook and Plotly | Modern Data

  76. R, Python, MATLAB, & Excel Dashboards & Graphs with D3.js & WebGL | Modern Data

  77. 100x faster Plotly graphs in IPython notebook | Modern Data

  78. Python Tools for Visual Studio

  79. matplotlib: python plotting — Matplotlib 1.4.3 documentation

  80. Why I push for Python, Python vs. Matlab

  81. Optimize Python with Closures « late.am

  82. Kivy: Cross-platform Python Framework for NUI

  83. KivEnt

  84. IronPython Python implementation

  85. ggplot | Home

  86. Python (programming language) - Wikipedia, the free encyclopedia)

  87. Welcome to PyCUDA’s documentation!

  88. What’s New — xlwings 0.3.5 documentation

  89. Python interpreters

  90. Welcome to Bokeh — Bokeh 0.9.0 documentation

  91. ŷhat | Rodeo: A data science IDE for Python

  92. .py in the sky

  93. Data Science Wars: R vs. Python | Data Science 101

  94. Table of Contents

  95. Python reserved words

  96. Python vs compiled languages

  97. Python standard library - Batteries included

  98. Python 2 vs 3

  99. notebook make interactive plots

  100. Raspberry Pi

  101. Cython: C-Extensions for Python - Annotated

  102. "PyFormat: Using % and .format() for great good!"

In [ ]: