Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3

Size: px
Start display at page:

Download "Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3"

Transcription

1 Notater: INF3331 Veronika Heimsbakk December 4, 2013 Contents 1 Introduction 3 2 Bash Variables Loops For loop Pipes Functions Basic Python Variables Lists and tuples Strings Conditionals Loops Functions Read from file Using modules Classes Stuff that is nice to know Copy, rename and remove files Traverse directory tree

2 5 Regular expression Special chars Common expressions Quoting special characters Handy functions Examples of regex Scientific or decimal or integer notation Numerical Python Operations on NumPy arrays Example of Python and NumPy Vectorization of a function Web applications in Python CGI

3 1 Introduction I took INF Problem solving with high-level languages in the fall These notes consists of a summary of my weekly assignments, lectures slides and resources online. 2 Bash Use plain Bourne shell (/bin/sh) when special features of Bash (/bin/bash) are not needed. 2.1 Variables Variables in Bash are untyped. 1 x = 3 2 y = 2 3 z = $x+$y 4 echo $z # output z = $ ( ( x+y ) ) 7 ( ( v=x+y ) ) 8 l e t w = x+y 9 echo $z $v $w # output Handle variables as they where strings, unless they are explicit declared as an Integer: 1 d e c l a r e i x = 3 Example of handling as string: 1 i f [ $?!= 0 ] ; then # s a f e 2 i f [ $?!= 0 ] ; then # may be unsafe Command line arguments are accessed like this: 1 $1 $2 $3 $4 # and s o on And they are initialised as this: 3

4 1 r=$1 # f o r f i r s t argument You may also store Unix-commands in variables: 1 s = echo s ( $r ) bc 1 or 1 s = $ ( echo s ( $r ) bc 1 ) 2.2 Loops For loop Following script is removing all.tmp-files at its location. 1 f i l e s = / bin / l s. tmp 2 # use / bin / l s in case l s i s a l i a s e d 3 4 f o r f i l e in $ f i l e s 5 do 6 echo removing $ f i l e 7 rm f $ f i l e 8 done C-style for loop: 1 d e c l a r e i i 2 f o r ( ( i =0; i<$n ; i ++)) ; do 3 echo $c 4 done 2.3 Pipes Output from one command can be sent as input to another through a pipe. For sending files with size to reverse numerical sort (-rn) and get a list of files sorted after size: 1 / bin / l s s s o r t r 4

5 2.4 Functions Example of a function with argument: 1 f u n c t i o n q u i t { 2 e x i t 3 } 4 f u n c t i o n e { 5 echo $1 6 } 7 e Hello # c a l l i n g e with argument Hello 8 e World # c a l l i n g e with argument World 9 q u i t # c a l l i n g q u i t 3 Basic Python 1 #! / usr / bin /env python 2 3 p r i n t Hello, World!../code/hw.py To run Python, simply type ~$ python yourprogram.py <argument1> <argument2> Variables Variables in Python hold references to objects of any type. 1 a = 3 2 a = a = 3 4 a = [ 1, 2 ] 5 6 # t e s t f o r var type 7 i f i s i n s t a n c e ( a, i n t ) : # i n t? 8 i f i s i n s t a n c e ( a, ( l i s t, t u p l e ) : # l i s t or t u p l e? Common types in Python: Numbers: int, float, complex../code/var.py Sequences: str (string), list, tuple, NumPy array 5

6 Mappings: dict (dictionary/hash) User-defined type in terms of a class 3.2 Lists and tuples 1 m y l i s t = [ a, 2. 5, 42, b ] 2 mytuple = ( a, 2. 5, 42, b ] 3 m y l i s t [ 1 ] = 10 4 m y l i s t. append ( c ) 5 mytuple [ 1 ] = 10 # i l l e g a l, cannot change a t u p l e List functionality../code/li.py 1 a = [ ] # i n i t empty l i s t 2 a = [ 1, b ] # i n i t a l i s t 3 a. append ( e ) # add e to end o f l i s t 4 a + [ 1, 3 ] # add two l i s t s 5 a [ 3 ] # index a l i s t element 6 a [ 1] # get l a s t l i s t element 7 a [ 1 : 3 ] # copy data to s u b l i s t, here : index 1,2 8 d e l a [ 3 ] # d e l e t e element at index 3 9 a. remove ( 1 ) # remove element with value 1 10 a. index ( b ) # f i n d index with value b 11 b in a # t e s t i f value b e x s i s t in l i s t 12 a. count ( v ) # count number o f elements with value v 13 l e n ( a ) # number o f elements in a 14 min ( a ) # s m a l l e s t element in a 15 max( a ) # l a r g e s t element in a 16 sum( a ) # add a l l elements in a 17 a. s o r t ( ) # s o r t l i s t a ( changes a ) 18 as = s o r t e d ( a ) # s o r t l i s t a ( r e t u r n s new l i s t ) 19 a. r e v e r s e ( ) # r e v e r s e l i s t a ( changes a ) 20 b [ 3 ] [ 0 ] [ 2 ] # nested l i s t indexing 3.3 Strings../code/li2.py 1 s1 = somestring with number %g % r 2 s2 = another s t r i n g 3 t e x t = 4 here you may w r i t e 6

7 5 a l o t o f t e x t on 6 m u l t i p l e l i n e s 7 8 # S t r i n g o p e r a t i o n s 9 s = some#s t r i n g somestring 10 s [ 8 : 1 0 ] # e x t r a c t s u b s t r i n g 11 s. f i n d ( i ) # index where i i s found 12 s. s p l i t ( # ) # s p l i t i n t o s u b s t r i n g s 13 some in s # t e s t i f s u b s t r i n g i s in s 14 s. r e p l a c e ( i, s ) 15 s. lower ( ) # lower case only 16 s. upper ( ) # upper case only 17 s. s t r i p ( ) # remove blanks 18,. j o i n ( s1 ) 3.4 Conditionals 1 i f c o n d i t i o n : 2 # block o f statements 3 e l i f c o n d i t i o n : 4 # block o f statements 5 e l s e : 6 # block o f statements 3.5 Loops 1 while c o n d i t i o n : 2 # block o f statements 3 4 f o r element in s o m e l i s t : 5 # block o f statements 6 7 # Ranges and l o o p s 8 f o r i in range (10) : 9 p r i n t ( i ) 3.6 Functions../code/str.py../code/con.py../code/loop.py 1 def f i b ( n ) : # w r i t e Fibonacci s e r i e s up to n 2 Print a Fibonacci s e r i e s up to n 7

8 3 a, b = 0, 1 4 while b < n : 5 p r i n t b, 6 a, b = b, a+b 7 8 # Now c a l l the f u n c t i o n we j u s t d e f i n e d : 9 f i b (2000) 3.7 Read from file../code/func.py 1 # With for loop 2 f i l e = open ( n e w f i l e. txt, r ) 3 f o r l i n e in f i l e : 4 p r i n t l i n e 5 6 # With statement 7 with open ( newtext. txt ) as f i l e : 8 data = f i l e. read ( ) 9 # do something with data # Read i n t o l i s t 12 with open ( h e l l o. txt ) as f : 13 data = f. r e a d l i n e s ( ) 3.8 Using modules../code/read.py 1 import sys 2 3 # Will s t o r e f i r s t command l i n e argument in x 4 x = f l o a t ( sys. argv [ 1 ] ) 5 6 # Same s h i t : 7 from s y s import argv 8 x = f l o a t ( argv [ 1 ] ) 3.9 Classes../code/mod.py All functions are virtual. No private or protected variables. self is a reference to this object. Data members are prefixed by self. 8

9 1 c l a s s MyClass : 2 def i n i t ( s e l f, i, j ) : # c t o r 3 s e l f. i = i ; s e l f. j = j 4 5 def w r i t e ( s e l f ) : 6 p r i n t MyClass : i=, s e l f. i, j=, s e l f. j../code/simpleclass.py 4 Stuff that is nice to know 4.1 Copy, rename and remove files 1 # Copy a f i l e 2 import s h u t i l 3 s h u t i l. copy ( myfile, t m p f i l e ) 4 5 # Rename a f i l e 6 import os 7 os. rename ( myfile, tmp. 1 ) 8 9 # Remove a f i l e 10 os. remove ( mydata )../code/crr.py 4.2 Traverse directory tree 1 import os 2 3 f o r dirname, dirnames, f i l e n a m e s in os. walk (. ) : 4 # p r i n t path to a l l s u b d i r e c t o r i e s f i r s t. 5 f o r subdirname i n dirnames : 6 p r i n t os. path. j o i n ( dirname, subdirname ) 7 8 # p r i n t path to a l l f i l e n a m e s. 9 f o r f i l e n a m e in f i l e n a m e s : 10 p r i n t os. path. j o i n ( dirname, f i l e n a m e )../code/trav.py 9

10 5 Regular expression 5.1 Special chars. any single character except newline ˆ the beginning of the line or string $ the end of line or string * zero or more of the last character + one or more of the last character? zero or one of the last character [A-Z ] match all upper case letters [abc ] match either a or b or c [ˆb ] does not match b [ˆa-z ] does not match lower case.* any sequence of characters (except newline) [.* ] the characters. and * ˆno the string no at the beginning of a line [ˆno ] neither n or o A-Z the 3-character string A-Z (eg le) gs match eggs or legs 5.2 Common expressions \n a newline \t a tab \w any alphanumeric (word) character, the same as [a-za-z0-9) ] \W any non-word character, the same as [^a-za-z0-9) ] \d any digit, the same as [0-9] 10

11 \D any non-digit, the same as [^0-9] \s any white space character: space, tab, newline etc. \S any non-white space character \b a word boundary, outside [] only \B no word boundary 5.3 Quoting special characters \. a dot \ a vertical bar \[ a open square bracket \) a closing parenthesis \ˆ a hat \\ a backslash. And so on Handy functions 1 import re 2 3 # compile regex pattern to regex o b j e c t 4 # to be used f o r match ( ) and search ( ) 5 re. compile ( pattern ) 6 7 # scans s t r i n g f o r a l o c a t i o n where regex 8 # produces a match. Returns MatchObject. 9 re. search ( pattern, s t r i n g ) # i f zero or more chars at beginning o f s t r i n g 12 # the regex r e t u r n s a corresponding MatchObject. 13 re. match ( pattern, s t r i n g ) # s p l i t s t r i n g by the o c curences o f pattern 16 re. s p l i t ( pattern, s t r i n g ) 11

12 17 18 # r e t u r n s a l l non o v e r l a p p i n g matches o f 19 # pattern in s t r i n g, as a l i s t o f s t r i n g s. 20 re. f i n d a l l ( pattern, s t r i n g ) 5.5 Examples of regex../code/regexfunc.py Scientific or decimal or integer notation 1 # One l i n e r : 2 pattern = r?(\d \.? \ d [ Ee][+\ ]?\d+ (\d+\.\d \ d \.\ d+) \ d +) 3 4 # Modularized : 5 r e a l i n = r \d+ 6 r e a l d n = r (\ d+\.\d \ d \.\ d+) 7 r e a l s n = r (\ d \.? \ d [ Ee][+\ ]?\d+ 8 r e a l =?( + r e a l s n + + r e a l d n + + r e a l i n + ) 6 Numerical Python../code/regexnum.py NumPy enables efficient numerical computing in Python. This is a package of modules, which offers efficient arrays with associated array operations coded in C or Fortran. 1 from numpy import 6.1 Operations on NumPy arrays 1 array ( ) # c r e a t e s a new array 2 z e r o s ( x ) # f i l l s the new array with x z e r o s 3 shape ( v,w) # turns i t i n t o a v times w matrix 4 reshape ( v,w) # r e t u r n s an array with the same 5 # data, but a new shape 6 f i l l ( x ) # f i l l array with s c a l a r value x 7 copy # r e t u r n s a copy o f the array 8 9 # Basic array indexing 12

13 10 a [ 2 : 4 ] = 1 # s e t a [ 2 ] and a [ 3 ] equal to 1 11 a [ 1] = a [ 0 ] # s e t l a s t elem equal to f i r s t elem 12 a [ : ] = 0 # s e t a l l elements to 0 13 a [ i, j ] = 10 # assignment to element ( i, j ) 14 p r i n t a [ :, k ] # p r i n t column with index k 15 p r i n t a [ 1, : ] # p r i n t second row 16 p r i n t a [ 0, 1 ] # p r i n t element ( 0, 1 )../code/numpy.py 6.2 Example of Python and NumPy Vectorization of a function 1 #! / usr / bin /env python 2 from numpy import 3 4 def i n i t i a l c o n d ( x ) : 5 i f type ( x ) == type ( array ( [ ] ) ) : 6 r e s u l t = z e r o s ( x. shape ) 7 r e s u l t. f i l l ( 3. 0 ) 8 r e turn r e s u l t 9 10 i f name == m a i n : 11 p r i n t i n i t i a l c o n d ( array ( z e r o s ( 6 ) ). reshape ( 3, 2 ) )../code/numpyvec.py 7 Web applications in Python 7.1 CGI Example with Python, HTML and CGI. Computes sine of a number from user input. 1 <html> 2 <form a c t i o n= hwhtml. py. c g i method= post > 3 Hello, World! The s i n e o f 4 <input type= t e x t name= r s i z e= 10 value= 1. 2 > 5 <input type= submit value= e q u a l s name= equalsbutton > 6 </ form> 7 </html>../code/hw.html 13

14 1 #! / s t o r e / bin /python 2 import cgi, math 3 p r i n t Content type : t e x t /html\n 4 5 form = c g i. F i e l d S t o r a g e ( ) 6 r = form. g e t v a l u e ( r ) 7 i f r i s not None : 8 s = s t r ( math. s i n ( f l o a t ( r ) ) 9 e l s e : 10 s = ; r =../code/hwhtml.py Do not bother to start with CGI. Rather check out Django. References [1] Langtangen, Hans Petter and Sundnes, Joakim, Lectures. University of Oslo, Dept. of Informatics, [2] Python documentation 14

1 Opening URLs. 2 Regular Expressions. 3 Look Back. 4 Graph Theory. 5 Crawler / Spider

1 Opening URLs. 2 Regular Expressions. 3 Look Back. 4 Graph Theory. 5 Crawler / Spider 1 Opening URLs 2 Regular Expressions 3 Look Back 4 Graph Theory 5 Crawler / Spider Sandeep Sadanandan (TU, Munich) Python For Fine Programmers June 5, 2009 1 / 14 Opening URLs The module used for opening

More information

Introduction to Language Theory and Compilation: Exercises. Session 2: Regular expressions

Introduction to Language Theory and Compilation: Exercises. Session 2: Regular expressions Introduction to Language Theory and Compilation: Exercises Session 2: Regular expressions Regular expressions (RE) Finite automata are an equivalent formalism to regular languages (for each regular language,

More information

Introduction to Python

Introduction to Python Introduction to Python Luis Pedro Coelho Institute for Molecular Medicine (Lisbon) Lisbon Machine Learning School II Luis Pedro Coelho (IMM) Introduction to Python Lisbon Machine Learning School II (1

More information

Python & Numpy A tutorial

Python & Numpy A tutorial Python & Numpy A tutorial Devert Alexandre School of Software Engineering of USTC 13 February 2012 Slide 1/38 Table of Contents 1 Why Python & Numpy 2 First steps with Python 3 Fun with lists 4 Quick tour

More information

2 Getting Started with Numerical Computations in Python

2 Getting Started with Numerical Computations in Python 1 Documentation and Resources * Download: o Requirements: Python, IPython, Numpy, Scipy, Matplotlib o Windows: google "windows download (Python,IPython,Numpy,Scipy,Matplotlib" o Debian based: sudo apt-get

More information

Python. chrysn

Python. chrysn Python chrysn 2008-09-25 Introduction Structure, Language & Syntax Strengths & Weaknesses Introduction Structure, Language & Syntax Strengths & Weaknesses Python Python is an interpreted,

More information

Introduction to Python

Introduction to Python Introduction to Python Luis Pedro Coelho luis@luispedro.org @luispedrocoelho European Molecular Biology Laboratory Lisbon Machine Learning School 2015 Luis Pedro Coelho (@luispedrocoelho) Introduction

More information

Scripting Languages Fast development, extensible programs

Scripting Languages Fast development, extensible programs Scripting Languages Fast development, extensible programs Devert Alexandre School of Software Engineering of USTC November 30, 2012 Slide 1/60 Table of Contents 1 Introduction 2 Dynamic languages A Python

More information

Introduction to Python for Biologists

Introduction to Python for Biologists Introduction to Python for Biologists Katerina Taškova 1 Jean-Fred Fontaine 1,2 1 Faculty of Biology, Johannes Gutenberg-Universität Mainz, Mainz, Germany 2 Genomics and Computational Biology, Kernel Press,

More information

Functions in Python L435/L555. Dept. of Linguistics, Indiana University Fall Functions in Python. Functions.

Functions in Python L435/L555. Dept. of Linguistics, Indiana University Fall Functions in Python. Functions. L435/L555 Dept. of Linguistics, Indiana University Fall 2016 1 / 18 What is a function? Definition A function is something you can call (possibly with some parameters, i.e., the things in parentheses),

More information

COMS 6100 Class Notes

COMS 6100 Class Notes COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran

More information

Scientific Programming in C XIII. Shell programming

Scientific Programming in C XIII. Shell programming Scientific Programming in C XIII. Shell programming Susi Lehtola 11 December 2012 Introduction Often in scientific computing one needs to do simple tasks related to renaming of files file conversions unit

More information

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology Tutorial Graz University of Technology March 22, 2010 Why? is: very readable easy to learn interpreted & interactive like a UNIX shell, only better object-oriented but not religious about it slower than

More information

CS177 Fall Midterm 1. Wed 10/07 6:30p - 7:30p. There are 25 multiple choice questions. Each one is worth 4 points.

CS177 Fall Midterm 1. Wed 10/07 6:30p - 7:30p. There are 25 multiple choice questions. Each one is worth 4 points. CS177 Fall 2015 Midterm 1 Wed 10/07 6:30p - 7:30p There are 25 multiple choice questions. Each one is worth 4 points. Answer the questions on the bubble sheet given to you. Only the answers on the bubble

More information

LAST TIME..THE COMMAND LINE

LAST TIME..THE COMMAND LINE LAST TIME..THE COMMAND LINE Maybe slightly to fast.. Finder Applications Utilities Terminal The color can be adjusted and is simply a matter of taste. Per default it is black! Dr. Robert Kofler Introduction

More information

L435/L555. Dept. of Linguistics, Indiana University Fall 2016

L435/L555. Dept. of Linguistics, Indiana University Fall 2016 in in L435/L555 Dept. of Linguistics, Indiana University Fall 2016 1 / 13 in we know how to output something on the screen: print( Hello world. ) input: input() returns the input from the keyboard

More information

6. How Functions Work and Are Accessed. Topics: Modules and Functions More on Importing Call Frames

6. How Functions Work and Are Accessed. Topics: Modules and Functions More on Importing Call Frames 6. How Functions Work and Are Accessed Topics: Modules and Functions More on Importing Call Frames Let s Talk About Modules What Are They? M1.py A module is a.py file that contains Python code The name

More information

Practical Information

Practical Information MA2501 Numerical Methods Spring 2018 Norwegian University of Science and Technology Department of Mathematical Sciences Semester Project Practical Information This project counts for 30 % of the final

More information

Lexical Analysis Part II: Constructing a Scanner from Regular Expressions

Lexical Analysis Part II: Constructing a Scanner from Regular Expressions Lexical Analysis Part II: Constructing a Scanner from Regular Expressions CS434 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper, Ken Kennedy

More information

Algorithms for Uncertainty Quantification

Algorithms for Uncertainty Quantification Technische Universität München SS 2017 Lehrstuhl für Informatik V Dr. Tobias Neckel M. Sc. Ionuț Farcaș April 26, 2017 Algorithms for Uncertainty Quantification Tutorial 1: Python overview In this worksheet,

More information

Lexical Analysis: DFA Minimization & Wrap Up

Lexical Analysis: DFA Minimization & Wrap Up Lexical Analysis: DFA Minimization & Wrap Up Automating Scanner Construction PREVIOUSLY RE NFA (Thompson s construction) Build an NFA for each term Combine them with -moves NFA DFA (subset construction)

More information

MiniMat: Matrix Language in OCaml LLVM

MiniMat: Matrix Language in OCaml LLVM Terence Lim - tl2735@columbia.edu August 17, 2016 Contents 1 Introduction 4 1.1 Goals........................................ 4 1.1.1 Flexible matrix notation......................... 4 1.1.2 Uncluttered................................

More information

Problem Set 5 Solutions

Problem Set 5 Solutions UNIVERSITY OF ALABAMA Department of Physics and Astronomy PH 25 / LeClair Spring 2009. Problem 7.5 from your textbook Problem Set 5 Solutions (a) We are given the initial and final position vectors d i

More information

Homework 1. Johan Jensen ABSTRACT. 1. Theoretical questions and computations related to digital representation of numbers.

Homework 1. Johan Jensen ABSTRACT. 1. Theoretical questions and computations related to digital representation of numbers. Homework 1 Johan Jensen This homework has three parts. ABSTRACT 1. Theoretical questions and computations related to digital representation of numbers. 2. Analyzing digital elevation data from the Mount

More information

Assignment 1: Due Friday Feb 6 at 6pm

Assignment 1: Due Friday Feb 6 at 6pm CS1110 Spring 2015 Assignment 1: Due Friday Feb 6 at 6pm You must work either on your own or with one partner. If you work with a partner, you and your partner must first register as a group in CMS and

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk I. Yu, D. Karabeg INF2220: algorithms and data structures Series 1 Topic Function growth & estimation of running time, trees (Exercises with hints for solution)

More information

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course. C PROGRAMMING 1 INTRODUCTION This is not a full c-programming course. It is not even a full 'Java to c' programming course. 2 LITTERATURE 3. 1 FOR C-PROGRAMMING The C Programming Language (Kernighan and

More information

UNIVERSITETET I OSLO

UNIVERSITETET I OSLO UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: INF1100 Introduction to programming with scientific applications Day of examination: Thursday, October 13, 2011 Examination

More information

jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text

jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text On the menu today jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text 1 jflap Demo jflap: Useful tool for creating and testing abstract machines Finite automata,

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation Closure properties of Regular Languages Pumping Theorem Your Questions? Previous class days' material Reading Assignments HW 6 or 7 problems Anything else 1 Regular Expressions

More information

Lectures about Python, useful both for beginners and experts, can be found at (http://scipy-lectures.github.io).

Lectures about Python, useful both for beginners and experts, can be found at  (http://scipy-lectures.github.io). Random Matrix Theory (Sethna, "Entropy, Order Parameters, and Complexity", ex. 1.6, developed with Piet Brouwer) 2016, James Sethna, all rights reserved. This is an ipython notebook. This hints file is

More information

/Users/jenskremkow/Science/Courses/python-summerschool-berlin/faculty/Day2/examples numpy.py September 2,

/Users/jenskremkow/Science/Courses/python-summerschool-berlin/faculty/Day2/examples numpy.py September 2, /Users/jenskremkow/Science/Courses/python-summerschool-berlin/faculty/Day2/examples numpy.py September 2, 2009 1 Numpy Many of the examples are taken from: http://www.scipy.org/cookbook Building Arrays

More information

How do regular expressions work? CMSC 330: Organization of Programming Languages

How do regular expressions work? CMSC 330: Organization of Programming Languages How do regular expressions work? CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata What we ve learned What regular expressions are What they can express, and cannot

More information

Computational modeling

Computational modeling Computational modeling Lecture 1 : Linear algebra - Matrix operations Examination next week: How to get prepared Theory and programming: Matrix operations Instructor : Cedric Weber Course : 4CCP1 Schedule

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 3, 2014 at 08:38 CS429 Slideset C: 1

More information

An Introduction to MAGMA

An Introduction to MAGMA An Introduction to MAGMA Don Taylor The University of Sydney 13 February 2012 Don Taylor (The University of Sydney) Magma Programming 13 February 2012 1 / 31 A little history MAGMA is a programming language

More information

Supplementary Material

Supplementary Material Supplementary Material Contents 1 Keywords of GQL 2 2 The GQL grammar 3 3 THE GQL user guide 4 3.1 The environment........................................... 4 3.2 GQL projects.............................................

More information

Tox Issues with virtualenv GNU Guix guix-tox. Guix-tox. A functional version of tox. Cyril Roelandt January 30, /35

Tox Issues with virtualenv GNU Guix guix-tox. Guix-tox. A functional version of tox. Cyril Roelandt January 30, /35 A functional version of tox cyril@redhat.com January 30, 2016 1/35 OpenStack developer at Red Hat since 2013 developer 2/35 1 2 Only Python packages can be installed Reproducibility One package manager

More information

CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community

CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Python basics (a) The programming language Python (circle the best answer): i. is primarily

More information

Data Intensive Computing Handout 11 Spark: Transitive Closure

Data Intensive Computing Handout 11 Spark: Transitive Closure Data Intensive Computing Handout 11 Spark: Transitive Closure from random import Random spark/transitive_closure.py num edges = 3000 num vertices = 500 rand = Random(42) def generate g raph ( ) : edges

More information

6.001 Recitation 22: Streams

6.001 Recitation 22: Streams 6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris

More information

E23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101

E23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101 E23: Hotel Management System Author: 1302509 Zhao Ruimin 1301478 Wen Yunlu 1302575 Hu Xing 1301911 Chen Ke 1302599 Tang Haoyuan Module: EEE 101 Lecturer: Date: Dr.Lin December/22/2014 Contents Contents

More information

n CS 160 or CS122 n Sets and Functions n Propositions and Predicates n Inference Rules n Proof Techniques n Program Verification n CS 161

n CS 160 or CS122 n Sets and Functions n Propositions and Predicates n Inference Rules n Proof Techniques n Program Verification n CS 161 Discrete Math at CSU (Rosen book) Sets and Functions (Rosen, Sections 2.1,2.2, 2.3) TOPICS Discrete math Set Definition Set Operations Tuples 1 n CS 160 or CS122 n Sets and Functions n Propositions and

More information

Introduction to Python and its unit testing framework

Introduction to Python and its unit testing framework Introduction to Python and its unit testing framework Instructions These are self evaluation exercises. If you know no python then work through these exercises and it will prepare yourself for the lab.

More information

More Dynamic Programming

More Dynamic Programming CS 374: Algorithms & Models of Computation, Spring 2017 More Dynamic Programming Lecture 14 March 9, 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 42 What is the running time of the following? Consider

More information

Practical Bioinformatics

Practical Bioinformatics 4/24/2017 Resources Course website: http://histo.ucsf.edu/bms270/ Resources on the course website: Syllabus Papers and code (for downloading before class) Slides and transcripts (available after class)

More information

More Dynamic Programming

More Dynamic Programming Algorithms & Models of Computation CS/ECE 374, Fall 2017 More Dynamic Programming Lecture 14 Tuesday, October 17, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 48 What is the running time of the following?

More information

Google Go illustrated on the basis of Fibonacci numbers

Google Go illustrated on the basis of Fibonacci numbers Google Go illustrated on the basis of Fibonacci numbers Jan Pennekamp RWTH University Aachen Chair for Data Management and Data Exploration Prof. Dr. T. Seidl Supervision: Dipl.-Ing. Marwan Hassani Friday,

More information

I. Numerical Computing

I. Numerical Computing I. Numerical Computing A. Lectures 1-3: Foundations of Numerical Computing Lecture 1 Intro to numerical computing Understand difference and pros/cons of analytical versus numerical solutions Lecture 2

More information

NumPy 1.5. open source. Beginner's Guide. v g I. performance, Python based free open source NumPy. An action-packed guide for the easy-to-use, high

NumPy 1.5. open source. Beginner's Guide. v g I. performance, Python based free open source NumPy. An action-packed guide for the easy-to-use, high NumPy 1.5 Beginner's Guide An actionpacked guide for the easytouse, high performance, Python based free open source NumPy mathematical library using realworld examples Ivan Idris.; 'J 'A,, v g I open source

More information

VPython Class 2: Functions, Fields, and the dreaded ˆr

VPython Class 2: Functions, Fields, and the dreaded ˆr Physics 212E Classical and Modern Physics Spring 2016 1. Introduction VPython Class 2: Functions, Fields, and the dreaded ˆr In our study of electric fields, we start with a single point charge source

More information

Regular languages, regular expressions, & finite automata (intro) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Regular languages, regular expressions, & finite automata (intro) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/ Regular languages, regular expressions, & finite automata (intro) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/ 1 L = {hello, bonjour, konnichiwa, } Σ = {a, b, c,, y, z}!2 Σ = {a, b, c,, y, z} Σ*

More information

Take-home Lab 1. Arrays

Take-home Lab 1. Arrays Take-home Lab 1 Arrays Findx 2-Dimensional Array Graded! Submit by Friday 23:59 Find You are given a treasure map by your friend Map is divided into R by C cells Super Marks The Spot You need to find all

More information

DARN: A Matrix Manipulation Language

DARN: A Matrix Manipulation Language DARN: A Matrix Manipulation Language Daisy Chaussee (dac2183) Anthony Kim (ak3703) Rafael Takasu (rgt2108) Ignacio (Nacho) Torras (it2216) December 20, 2016 1 Contents 1 Introduction to the Language 4

More information

: Intro Programming for Scientists and Engineers Assignment 4: Learning from Echocardiograms

: Intro Programming for Scientists and Engineers Assignment 4: Learning from Echocardiograms Assignment 4: Learning from Echocardiograms Page 1 600.112: Intro Programming for Scientists and Engineers Assignment 4: Learning from Echocardiograms Peter H. Fröhlich phf@cs.jhu.edu Joanne Selinski joanne@cs.jhu.edu

More information

MATH 137 : Calculus 1 for Honours Mathematics. Online Assignment #2. Introduction to Sequences

MATH 137 : Calculus 1 for Honours Mathematics. Online Assignment #2. Introduction to Sequences 1 MATH 137 : Calculus 1 for Honours Mathematics Online Assignment #2 Introduction to Sequences Due by 9:00 pm on WEDNESDAY, September 19, 2018 Instructions: Weight: 2% This assignment covers the topics

More information

Moving into the information age: From records to Google Earth

Moving into the information age: From records to Google Earth Moving into the information age: From records to Google Earth David R. R. Smith Psychology, School of Life Sciences, University of Hull e-mail: davidsmith.butterflies@gmail.com Introduction Many of us

More information

Computation Theory Finite Automata

Computation Theory Finite Automata Computation Theory Dept. of Computing ITT Dublin October 14, 2010 Computation Theory I 1 We would like a model that captures the general nature of computation Consider two simple problems: 2 Design a program

More information

Who am I? Math 1080: Numerical Linear Algebra. Books. Format

Who am I? Math 1080: Numerical Linear Algebra. Books. Format Who am I? Math 18: Numerical Linear Algebra M M Sussman sussmanm@mathpittedu Office Hours: MW 1:45PM-2:45PM, Thack 622 Part-time faculty in Math Dept Experience at Bettis lab Administer 27/271 Numerical

More information

PRIMES Math Problem Set

PRIMES Math Problem Set PRIMES Math Problem Set PRIMES 017 Due December 1, 01 Dear PRIMES applicant: This is the PRIMES 017 Math Problem Set. Please send us your solutions as part of your PRIMES application by December 1, 01.

More information

PYTHON, NUMPY, AND SPARK. Prof. Chris Jermaine

PYTHON, NUMPY, AND SPARK. Prof. Chris Jermaine PYTHON, NUMPY, AND SPARK Prof. Chris Jermaine cmj4@cs.rice.edu 1 Next 1.5 Days Intro to Python for statistical/numerical programming (day one) Focus on basic NumPy API, using arrays efficiently Will take

More information

Data Structures in Java

Data Structures in Java Data Structures in Java Lecture 20: Algorithm Design Techniques 12/2/2015 Daniel Bauer 1 Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways of

More information

1 Alphabets and Languages

1 Alphabets and Languages 1 Alphabets and Languages Look at handout 1 (inference rules for sets) and use the rules on some examples like {a} {{a}} {a} {a, b}, {a} {{a}}, {a} {{a}}, {a} {a, b}, a {{a}}, a {a, b}, a {{a}}, a {a,

More information

A High Level Programming Language for Quantum Computing

A High Level Programming Language for Quantum Computing QUARK QUantum Analysis and Realization Kit A High Level Programming Language for Quantum Computing Team In lexicographical order: Name UNI Role Daria Jung djj2115 Verification and Validation Jamis Johnson

More information

CS Exam 1 Study Guide and Practice Exam

CS Exam 1 Study Guide and Practice Exam CS 150 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Suggestions, Warnings, and Resources.................................

More information

Databases through Python-Flask and MariaDB

Databases through Python-Flask and MariaDB 1 Databases through Python-Flask and MariaDB Tanmay Agarwal, Durga Keerthi and G V V Sharma Contents 1 Python-flask 1 1.1 Installation.......... 1 1.2 Testing Flask......... 1 2 Mariadb 1 2.1 Software

More information

Lab #1: Photon counting with a PM tube statistics of light James. R. Graham, UC Berkeley

Lab #1: Photon counting with a PM tube statistics of light James. R. Graham, UC Berkeley Lab #: Photon counting with a PM tube statistics of light James. R. Graham, UC Berkeley Your report is due on 2008, September 6 at 5:59:59PM PDT. NO EXTENSIONS! Overview. Schedule This is a two-week lab

More information

Contents. 6.1 Conditional statements 6.2 Iteration 6.3 Procedures and flow control

Contents. 6.1 Conditional statements 6.2 Iteration 6.3 Procedures and flow control Introduction This reference manual gives an essentially complete description of the standard facilities available in SMP. Extensive illustrative examples are included. The same text is given without these

More information

You will be writing code in the Python programming language, which you may have learnt in the Python module.

You will be writing code in the Python programming language, which you may have learnt in the Python module. Weather Logger Introduction: In this project you will collect data from the Sense HAT s sensors and log it to a file. Then you will use the PyGal module to display that data as a line graph. You will be

More information

Lab 6: Linear Algebra

Lab 6: Linear Algebra 6.1 Introduction Lab 6: Linear Algebra This lab is aimed at demonstrating Python s ability to solve linear algebra problems. At the end of the assignment, you should be able to write code that sets up

More information

Kurt Schmidt. June 5, 2017

Kurt Schmidt. June 5, 2017 Dept. of Computer Science, Drexel University June 5, 2017 Examples are taken from Kernighan & Pike, The Practice of ming, Addison-Wesley, 1999 Objective: To learn when and how to optimize the performance

More information

PYTHON AND DATA SCIENCE. Prof. Chris Jermaine

PYTHON AND DATA SCIENCE. Prof. Chris Jermaine PYTHON AND DATA SCIENCE Prof. Chris Jermaine cmj4@cs.rice.edu 1 Python Old language, first appeared in 1991 But updated often over the years Important characteristics Interpreted Dynamically-typed High

More information

Lexical Analysis. Reinhard Wilhelm, Sebastian Hack, Mooly Sagiv Saarland University, Tel Aviv University.

Lexical Analysis. Reinhard Wilhelm, Sebastian Hack, Mooly Sagiv Saarland University, Tel Aviv University. Lexical Analysis Reinhard Wilhelm, Sebastian Hack, Mooly Sagiv Saarland University, Tel Aviv University http://compilers.cs.uni-saarland.de Compiler Construction Core Course 2017 Saarland University Today

More information

10. Finite Automata and Turing Machines

10. Finite Automata and Turing Machines . Finite Automata and Turing Machines Frank Stephan March 2, 24 Introduction Alan Turing s th Birthday Alan Turing was a completely original thinker who shaped the modern world, but many people have never

More information

Black-Box Testing Techniques III

Black-Box Testing Techniques III Black-Box Testing Techniques III Software Testing and Verification Lecture 6 Prepared by Stephen M. Thebaut, Ph.D. University of Florida Another Cause-Effect Example: Symbol Table Storage Specification

More information

CompA - Complex Analyzer

CompA - Complex Analyzer CompA - Complex Analyzer Xiping Liu(xl2639), Jianshuo Qiu(jq2253), Tianwu Wang(tw2576), Yingshuang Zheng(yz3083), Zhanpeng Su(zs2329) Septembee 25, 2017 1 Introduction The motivation for writing this language

More information

CISC-102 Winter 2016 Lecture 11 Greatest Common Divisor

CISC-102 Winter 2016 Lecture 11 Greatest Common Divisor CISC-102 Winter 2016 Lecture 11 Greatest Common Divisor Consider any two integers, a,b, at least one non-zero. If we list the positive divisors in numeric order from smallest to largest, we would get two

More information

Quiz 1 Solutions. (a) f 1 (n) = 8 n, f 2 (n) = , f 3 (n) = ( 3) lg n. f 2 (n), f 1 (n), f 3 (n) Solution: (b)

Quiz 1 Solutions. (a) f 1 (n) = 8 n, f 2 (n) = , f 3 (n) = ( 3) lg n. f 2 (n), f 1 (n), f 3 (n) Solution: (b) Introduction to Algorithms October 14, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Srini Devadas and Constantinos (Costis) Daskalakis Quiz 1 Solutions Quiz 1 Solutions Problem

More information

Math.3336: Discrete Mathematics. Combinatorics: Basics of Counting

Math.3336: Discrete Mathematics. Combinatorics: Basics of Counting Math.3336: Discrete Mathematics Combinatorics: Basics of Counting Instructor: Dr. Blerina Xhabli Department of Mathematics, University of Houston https://www.math.uh.edu/ blerina Email: blerina@math.uh.edu

More information

Theory of Computation

Theory of Computation Theory of Computation Lecture #2 Sarmad Abbasi Virtual University Sarmad Abbasi (Virtual University) Theory of Computation 1 / 1 Lecture 2: Overview Recall some basic definitions from Automata Theory.

More information

Introduction to Theoretical Computer Science. Motivation. Automata = abstract computing devices

Introduction to Theoretical Computer Science. Motivation. Automata = abstract computing devices Introduction to Theoretical Computer Science Motivation Automata = abstract computing devices Turing studied Turing Machines (= computers) before there were any real computers We will also look at simpler

More information

MCS 260 Exam 2 13 November In order to get full credit, you need to show your work.

MCS 260 Exam 2 13 November In order to get full credit, you need to show your work. MCS 260 Exam 2 13 November 2015 Name: Do not start until instructed to do so. In order to get full credit, you need to show your work. You have 50 minutes to complete the exam. Good Luck! Problem 1 /15

More information

Worksheet 1: Integrators

Worksheet 1: Integrators Simulation Methods in Physics I WS 2014/2015 Worksheet 1: Integrators Olaf Lenz Alexander Schlaich Stefan Kesselheim Florian Fahrenberger Peter Košovan October 22, 2014 Institute for Computational Physics,

More information

Extracting Canadian Climate Data from Environment Canada dataset

Extracting Canadian Climate Data from Environment Canada dataset University of British Columbia Department of Statistics Technical Report #244 May 2009 Extracting Canadian Climate Data from Environment Canada dataset by Reza Hosseini 1 1 University of British Columbia

More information

Regular expressions and automata

Regular expressions and automata Regular expressions and automata Introduction Finite State Automaton (FSA) Finite State Transducers (FST) Regular expressions(i) (Res) Standard notation for characterizing text sequences Specifying text

More information

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ;

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ; CPSC 490 Input Input will always arrive on stdin. You may assume input is well-formed with respect to the problem specification; inappropriate input (e.g. text where a number was specified, number out

More information

Fundamentals of Computational Science

Fundamentals of Computational Science Fundamentals of Computational Science Dr. Hyrum D. Carroll August 23, 2016 Introductions Each student: Name Undergraduate school & major Masters & major Previous research (if any) Why Computational Science

More information

Thomas Jefferson Invitational Open in Informatics

Thomas Jefferson Invitational Open in Informatics Thomas Jefferson Invitational Open in Informatics Sample Problems (With Solutions) Version 2.01.1 By programmers, For programmers Preface Preface Welcome to the TJ IOI Sample Problems document. Here, you

More information

GRASS GIS Development APIs

GRASS GIS Development APIs GRASS GIS Development APIs Lifting the fog on the different ways to develop with and for GRASS Moritz Lennert Member of the GRASS GIS Project Steering Comittee PostGISomics Over 30 years of development

More information

2 - Strings and Binomial Coefficients

2 - Strings and Binomial Coefficients November 14, 2017 2 - Strings and Binomial Coefficients William T. Trotter trotter@math.gatech.edu Basic Definition Let n be a positive integer and let [n] = {1, 2,, n}. A sequence of length n such as

More information

CS 7B - Spring Assignment: Adapting the calculator for bitwise expressions. due 2/21/18

CS 7B - Spring Assignment: Adapting the calculator for bitwise expressions. due 2/21/18 CS 7B - Spring 2018 - Assignment: Adapting the calculator for bitwise expressions. due 2/21/18 Background Theory A bitwise number is a number in base 2. In base 2, place values are either a 1 or 0, depending

More information

Managing Uncertainty

Managing Uncertainty Managing Uncertainty Bayesian Linear Regression and Kalman Filter December 4, 2017 Objectives The goal of this lab is multiple: 1. First it is a reminder of some central elementary notions of Bayesian

More information

Modern Functional Programming and Actors With Scala and Akka

Modern Functional Programming and Actors With Scala and Akka Modern Functional Programming and Actors With Scala and Akka Aaron Kosmatin Computer Science Department San Jose State University San Jose, CA 95192 707-508-9143 akosmatin@gmail.com Abstract For many years,

More information

arxiv: v2 [cs.ds] 9 Nov 2017

arxiv: v2 [cs.ds] 9 Nov 2017 Replace or Retrieve Keywords In Documents At Scale Vikash Singh Belong.co Bangalore, India vikash@belong.co arxiv:1711.00046v2 [cs.ds] 9 Nov 2017 Abstract In this paper we introduce, the FlashText 1 algorithm

More information

Tasks of lexer. CISC 5920: Compiler Construction Chapter 2 Lexical Analysis. Tokens and lexemes. Buffering

Tasks of lexer. CISC 5920: Compiler Construction Chapter 2 Lexical Analysis. Tokens and lexemes. Buffering Tasks of lexer CISC 5920: Compiler Construction Chapter 2 Lexical Analysis Arthur G. Werschulz Fordham University Department of Computer and Information Sciences Copyright Arthur G. Werschulz, 2017. All

More information

On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Lab 5 : Linking Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The main objective of this lab is to experiment

More information

CS 177 Fall 2014 Midterm 1 exam - October 9th

CS 177 Fall 2014 Midterm 1 exam - October 9th CS 177 Fall 2014 Midterm 1 exam - October 9th There are 25 True/False and multiple choice questions. Each one is worth 4 points. Answer the questions on the bubble sheet given to you. Remember to fill

More information

Organization Team Team ID#

Organization Team Team ID# 1. [5] A positive integer is called primer if it has a prime number of distinct prime factors. Find the smallest primer number. 2. [5] Pascal has a triangle. In the nth row, there are n + 1 numbers a n,0,

More information

Problem Points Score Total 100

Problem Points Score Total 100 Final Exam A. Miller Spring 2005 Math 240 0 Show all work. No books, no calculators, no cell phones, no pagers, no electronic devices of any kind. However you can bring to the exam one 8.5 by 11 cheat

More information

Plan for Today and Beginning Next week (Lexical Analysis)

Plan for Today and Beginning Next week (Lexical Analysis) Plan for Today and Beginning Next week (Lexical Analysis) Regular Expressions Finite State Machines DFAs: Deterministic Finite Automata Complications NFAs: Non Deterministic Finite State Automata From

More information