Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction...

88
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 / 78)

Transcript of Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction...

Page 1: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

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 / 78)

Page 2: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Language History

Python was started in the late 80’s.It was intended to be both easy to teach and industrial strength.It is (has always been) open-source.It has become one of the most widely used languages (top 10).

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (2 / 78)

Page 3: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Versions

Python VersionsThere are two major versions, currently: 2.7 and 3.2.We are going to be using 2.7 (but 2.6 should be OK too).

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (3 / 78)

Page 4: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Example

pr in t ” He l lo World”

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (4 / 78)

Page 5: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Task

AverageCompute the average of the following numbers:

...1 10

...2 7

...3 22

...4 14

...5 17

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (5 / 78)

Page 6: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python example

numbers = [ 10 , 7 , 22 , 14 , 17 ]

sum = 0 . 0n = 0 . 0f o r va l in numbers :

sum = sum + valn = n + 1

return sum / n

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (6 / 78)

Page 7: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

“Python is executable pseudo-code.”—Python lore (often attributed to Bruce Eckel)

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (7 / 78)

Page 8: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Programming Basics

numbers = [ 10 , 7 , 22 , 14 , 17 ]

sum = 0 . 0n = 0 . 0f o r va l in numbers :

sum = sum + valn = n + 1

return sum / n

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (8 / 78)

Page 9: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types

Basic TypesNumbers (integers and floating point)StringsLists and tuplesDictionaries

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (9 / 78)

Page 10: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Numbers I: Integers

A = 1B = 2C = 3pr in t A+B*C

Outputs 7.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (10 / 78)

Page 11: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Numbers II: Floats

A = 1 . 2B = 2 . 4C = 3 . 6p r in t A + B*C

Outputs 9.84.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (11 / 78)

Page 12: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Numbers III: Integers & Floats

A = 2B = 2 . 5C = 4 . 4p r in t A + B*C

Outputs 22.0.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (12 / 78)

Page 13: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Composite Assignment

t o t a l = t o t a l + n

Can be abbreviated ast o t a l += n

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (13 / 78)

Page 14: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Strings

f i r s t = ’ John ’l a s t = ”Doe”f u l l = f i r s t + ” ” + l a s t

p r i n t f u l l

Outputs John Doe.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (14 / 78)

Page 15: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Strings

f i r s t = ’ John ’l a s t = ”Doe”f u l l = f i r s t + ” ” + l a s t

p r i n t f u l l

Outputs John Doe.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (14 / 78)

Page 16: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: String Rules

What is a String LiteralShort string literals are delimited by (”) or (’).Short string literals are one line only.Special characters are input using escape sequences.(\n for newline,…)

mul t ip l e = ’He : May I ?\nShe : No , you may not . ’a l t e r n a t i v e = ”He : May I ?\nShe : No , you may not . ”

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (15 / 78)

Page 17: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Long Strings

We can input a long string using triple quotes (”’ or ”””) as delimiters.long = ’ ’ ’ Te l l me , i s l oveS t i l l a popular sugge s t i onOr merely an ob so l e t e a r t ?

Forgive me, f o r asking ,This s imple quest ion ,I am un fami l i a r with h i s heart . ’ ’ ’

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (16 / 78)

Page 18: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Lists

cour s e s = [ ’ PfS ’ , ’ P o l i t i c a l Phi losophy ’ ]

p r i n t ”The the f i r s t course i s ” , c ou r s e s [ 0 ]p r i n t ”The second course i s ” , cour s e s [ 1 ]

Notice that list indices start at 0!

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (17 / 78)

Page 19: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Lists

mixed = [ ’Banana ’ , 100 , [ ’ Another ’ , ’ L i s t ’ ] , [ ] ]p r i n t l en (mixed )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (18 / 78)

Page 20: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Lists

f r u i t s = [ ’Banana ’ , ’ Apple ’ , ’ Orange ’ ]f r u i t s . s o r t ( )p r i n t f r u i t s

Prints [’Apple’, ’Banana’, ’Orange’]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (19 / 78)

Page 21: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Types: Dictionaries

emai l s = { ’ Luis ’ : ’ lpc@cmu . edu ’ ,’Mark ’ : ’mark@cmu . edu ’ }

p r i n t ” Luis ’ s emai l i s ” , emai l s [ ’ Luis ’ ]

ema i l s [ ’ Rita ’ ] = ’ rita@cmu . edu ’

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (20 / 78)

Page 22: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Control Structures

student = ’ Rita ’average = gradeavg ( student )i f average > 0 . 7 :

p r i n t student , ’ passed ! ’p r i n t ’ Congratu lat ions ! ! ’

e l s e :p r i n t student , ’ f a i l e d . Sorry . ’

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (21 / 78)

Page 23: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Python Blocks

Unlike almost all other modern programming languages,Python uses indentation to delimit blocks!i f <cond i t i on>:

statement 1statement 2statement 3

next statement

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (22 / 78)

Page 24: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Convention...1 Use 4 spaces to indent....2 Other things will work, but confuse people.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (23 / 78)

Page 25: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Conditionals

Examplesx == yx != yx < yx < y < zx in lstx not in lst

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (24 / 78)

Page 26: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Nested Blocks

i f <cond i t i on 1>:do somethingi f cond i t i on 2>:

nested blocke l s e :

nested e l s e b locke l i f <cond i t i on 1b>:

do something

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (25 / 78)

Page 27: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

For loop

s tudents = [ ’ Luis ’ , ’ Rita ’ , ’ Sabah ’ , ’Mark ’ ]f o r s t in s tudents :

p r i n t s t

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (26 / 78)

Page 28: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

While Loop

whi le <cond i t i on>:statement1statement2

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (27 / 78)

Page 29: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Other Loopy Stuff

f o r i in range ( 5 ) :p r i n t i

prints

01234

This is because range(5) is the list [0,1,2,3,4].

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (28 / 78)

Page 30: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Break

r i t a_en r o l l e d = Falsef o r s t in s tudents :

i f s t == ’ Rita ’ :r i t a_en r o l l e d = Truebreak

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (29 / 78)

Page 31: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Conditions & BooleansBooleansJust two values: True and False.Comparisons return booleans (e.g., x < 2)

ConditionsWhen evaluating a condition, the condition is converted to aboolean:Many things are converted to False:

...1 [] (the empty list)

...2 {} (the empty dictionary)

...3 ”” (the empty string)

...4 0 or 0.0 (the value zero)

...5 …

Everything else is True or not convertible to boolean.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (30 / 78)

Page 32: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Conditions Example

A = [ ]B = [ 1 , 2 ]C = 2D = 0

i f A:p r i n t ’A i s t rue ’

i f B:p r i n t ’B i s t rue ’

i f C:p r i n t ’C i s t rue ’

i f D:p r i n t ’D i s t rue ’

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (31 / 78)

Page 33: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Numbers

Two Types of Numbers...1 Integers...2 Floating-point

Operations...1 Unary Minus: -x...2 Addition: x + y...3 Subtraction: x - y...4 Multiplication: x * y...5 Exponentiation: x ** y

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (32 / 78)

Page 34: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Division

DivisionWhat is 9 divided by 3?What is 10 divided by 3?

Two types of division...1 Integer division: x // y

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (33 / 78)

Page 35: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Division

DivisionWhat is 9 divided by 3?What is 10 divided by 3?

Two types of division...1 Integer division: x // y

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (33 / 78)

Page 36: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Functions

de f double ( x ) :’ ’ ’y = double ( x )

Returns the double o f x’ ’ ’r e turn 2*x

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (34 / 78)

Page 37: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Functions

A=4pr in t double (A)p r in t double ( 2 . 3 )p r i n t double ( double (A) )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (35 / 78)

Page 38: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Linear Algebra Recap

VectorsMatrices (operators)Multiplication of vectors & Matrices

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (36 / 78)

Page 39: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Linear Algebra Recap

Vectors[0, 1.2,−1.2, 4] ∈ R4

Matrices (operators) 1 0 00 1 00 0 1

Multiplication of vectors & Matrices

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (36 / 78)

Page 40: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Vector Space

Addition operation

[1, 2] + [2, 3] = [3, 5]

Multiplication by a scalar

4 · [2, 0, 1] = [8, 0, 4]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (37 / 78)

Page 41: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrices (Linear Operators)

I =

1 0 00 1 00 0 1

This is the identity matrix

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (38 / 78)

Page 42: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix as an Operator

A00 A01 A02

A10 A11 A12

A20 A21 A22

x0x1x2

=

x0A00 + x1A01 + x2A02

x0A10 + x1A11 + x2A12

x0A20 + x1A21 + x2A22

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (39 / 78)

Page 43: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix as an Operator

1 0 00 1 00 0 1

x0x1x2

=

x0x1x2

This is identity.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (40 / 78)

Page 44: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix Transpose

A00 A01 A02

A10 A11 A12

A20 A21 A22

T

=

A00 A10 A20

A01 A11 A21

A02 A12 A22

1 2 34 5 67 8 9

T

=

1 4 72 5 83 6 9

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (41 / 78)

Page 45: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix Transpose

A00 A01 A02

A10 A11 A12

A20 A21 A22

T

=

A00 A10 A20

A01 A11 A21

A02 A12 A22

1 2 3

4 5 67 8 9

T

=

1 4 72 5 83 6 9

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (41 / 78)

Page 46: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Numeric Python: Numpy

Numpy

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (42 / 78)

Page 47: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Basic Type

numpy.array or numpy.ndarray.

Multi-dimensional array of numbers.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (43 / 78)

Page 48: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

numpy example

import numpy as npA = np . array ( [

[ 0 , 1 , 2 ] ,[ 2 , 3 , 4 ] ,[ 4 , 5 , 6 ] ,[ 6 , 7 , 8 ] ] )

p r i n t A[ 0 , 0 ]p r i n t A[ 0 , 1 ]p r i n t A[ 1 , 0 ]

012

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (44 / 78)

Page 49: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

numpy example

import numpy as npA = np . array ( [

[ 0 , 1 , 2 ] ,[ 2 , 3 , 4 ] ,[ 4 , 5 , 6 ] ,[ 6 , 7 , 8 ] ] )

p r i n t A[ 0 , 0 ]p r i n t A[ 0 , 1 ]p r i n t A[ 1 , 0 ]

012

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (44 / 78)

Page 50: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Why Numpy?

Why do we need numpy?import numpy as npl s t = [ 0 . , 1 . , 2 . , 3 . ]a r r = np . array ( [ 0 . , 1 . , 2 . , 3 . ] )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (45 / 78)

Page 51: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

A Python List of Numbers

..

float

.

0.0

.

float

.

1.0

.

float

.

2.0

.

float

.

3.0

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (46 / 78)

Page 52: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

A Numpy Array of Numbers

..float

.0.0

.1.0

.2.0

.3.0

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (47 / 78)

Page 53: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Numpy Arrays

AdvantagesLess memory consumptionFasterWork with (or write) code in other languages (C, C++, Fortran…)

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (48 / 78)

Page 54: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix-vector multiplication

A = np . array ( [[ 1 , 0 , 0 ] ,[ 0 , 1 , 0 ] ,[ 0 , 0 , 1 ] ] )

v = np . array ( [ 1 , 5 , 2 ] )

p r i n t np . dot (A, v )

[1 5 2]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (49 / 78)

Page 55: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix-vector multiplication

A = np . array ( [[ 1 , 0 , 0 ] ,[ 0 , 1 , 0 ] ,[ 0 , 0 , 1 ] ] )

v = np . array ( [ 1 , 5 , 2 ] )

p r i n t np . dot (A, v )

[1 5 2]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (49 / 78)

Page 56: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix-Matrix and Dot Products

(1 11 −1

)(0 11 0

)=

(1 1−1 1

)

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (50 / 78)

Page 57: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix-Matrix and Dot Products

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (51 / 78)

Page 58: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix-Matrix and Dot Products

(1 2

)·(

3−1

)= 1 · 3 + (−1) · 2 = 1.

This is a vector inner product (aka dot product)

< x⃗, y⃗ >= x⃗ · y⃗ = x⃗Ty⃗.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (52 / 78)

Page 59: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Dot Products: Norms

x⃗Tx⃗ =?

x⃗Tx⃗ =∑

ix2i

This is the squared norm of the vector (size).

∥x⃗∥ =√x⃗Tx⃗

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (53 / 78)

Page 60: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Dot Products: Norms

x⃗Tx⃗ =?

x⃗Tx⃗ =∑

ix2i

This is the squared norm of the vector (size).

∥x⃗∥ =√x⃗Tx⃗

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (53 / 78)

Page 61: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

v0 = np . array ( [ 1 , 2 ] )v1 = np . array ( [ 3 , - 1 ] )

r = 0 . 0f o r i in xrange ( 2 ) :

r += v0 [ i ] *v1 [ i ]p r i n t r

p r i n t np . dot ( v0 , v1 )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (54 / 78)

Page 62: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

A0 = np . array ( [ [ 1 , 2 ] , [ 2 , 3 ] ] )A1 = np . array ( [ [ 0 , 1 ] , [ 1 , 0 ] ] )

p r i n t np . dot (A0 ,A1) (0 22 3

)(0 11 0

)

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (55 / 78)

Page 63: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matrix Operation Properties

A+ B = B+AAB ̸= BA (in general)A(BC) = (AB)C

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (56 / 78)

Page 64: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Dot Product Properties

x⃗Ty⃗ ≥ 0

x⃗Tx⃗ = 0 iff x⃗ = 0⃗

x⃗Ty⃗ = y⃗Tx⃗ (for reals)α(⃗xTy⃗) = (αx⃗)Ty⃗x⃗Tz⃗+ y⃗Tz⃗ = (⃗x+ y⃗)T z⃗

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (57 / 78)

Page 65: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Some Array Properties

import numpy as npA = np . array ( [

[ 0 , 1 , 2 ] ,[ 2 , 3 , 4 ] ,[ 4 , 5 , 6 ] ,[ 6 , 7 , 8 ] ] )

p r i n t A. shapep r in t A. s i z e

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (58 / 78)

Page 66: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Some Array Functions

. . .p r i n t A.max( )p r i n t A. min ( )

max(): maximummin(): minimumptp(): spread (max - min)sum(): sumstd(): standard deviation…

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (59 / 78)

Page 67: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Other Functions

np.expnp.sin…

All of these work element-wise!

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (60 / 78)

Page 68: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Arithmetic Operations

import numpy as npA = np . array ( [ 0 , 1 , 2 , 3 ] )B = np . array ( [ 1 , 1 , 2 , 2 ] )

p r i n t A + Bpr in t A * Bpr in t A / B

Prints

array([1, 2, 4, 5])

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (61 / 78)

Page 69: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Arithmetic Operations

import numpy as npA = np . array ( [ 0 , 1 , 2 , 3 ] )B = np . array ( [ 1 , 1 , 2 , 2 ] )

p r i n t A + Bpr in t A * Bpr in t A / B

Prints

array([1, 2, 4, 5])

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (61 / 78)

Page 70: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Object Construction

import numpy as npA = np . array ( [ 0 , 1 , 1 ] , np . f l o a t 3 2 )A = np . array ( [ 0 , 1 , 1 ] , f l o a t )A = np . array ( [ 0 , 1 , 1 ] , bool )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (62 / 78)

Page 71: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Reduction

A = np . array ( [[ 0 , 0 , 1 ] ,[ 1 , 2 , 3 ] ,[ 2 , 4 , 2 ] ,[ 1 , 0 , 1 ] ] )

p r i n t A.max( 0 )p r i n t A.max( 1 )p r i n t A.max( )

prints

[2,4,3][1,3,4,1]4

The same is true for many other functions.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (63 / 78)

Page 72: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Slicing

import numpy as npA = np . array ( [

[ 0 , 1 , 2 ] ,[ 2 , 3 , 4 ] ,[ 4 , 5 , 6 ] ,[ 6 , 7 , 8 ] ] )

p r i n t A[ 0 ]p r i n t A[ 0 ] . shapep r in t A[ 1 ]p r i n t A[ : , 2 ]

[0, 1, 2](3,)[2, 3, 4][2, 4, 6, 8]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (64 / 78)

Page 73: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Slicing

import numpy as npA = np . array ( [

[ 0 , 1 , 2 ] ,[ 2 , 3 , 4 ] ,[ 4 , 5 , 6 ] ,[ 6 , 7 , 8 ] ] )

p r i n t A[ 0 ]p r i n t A[ 0 ] . shapep r in t A[ 1 ]p r i n t A[ : , 2 ]

[0, 1, 2](3,)[2, 3, 4][2, 4, 6, 8]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (64 / 78)

Page 74: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Slices Share Memory!

import numpy as npA = np . array ( [

[ 0 , 1 , 2 ] ,[ 2 , 3 , 4 ] ,[ 4 , 5 , 6 ] ,[ 6 , 7 , 8 ] ] )

B = A[ 0 ]B[ 0 ] = - 1p r in t A[ 0 , 0 ]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (65 / 78)

Page 75: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Pass is By Reference

de f double (A) :A *= 2

A = np . arange ( 20 )double (A)

A = np . arange ( 20 )B = A. copy ( )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (66 / 78)

Page 76: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Pass is By Reference

de f double (A) :A *= 2

A = np . arange ( 20 )double (A)

A = np . arange ( 20 )B = A. copy ( )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (66 / 78)

Page 77: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Logical Arrays

A = np . array ( [ - 1 , 0 , 1 , 2 , - 2 , 3 , 4 , - 2 ] )p r i n t (A > 0 )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (67 / 78)

Page 78: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Logical Arrays II

A = np . array ( [ - 1 , 0 , 1 , 2 , - 2 , 3 , 4 , - 2 ] )p r i n t ( (A > 0 ) & (A < 3 ) ) .mean( )

What does this do?

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (68 / 78)

Page 79: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Logical Indexing

A[A < 0 ] = 0

orA *= (A > 0 )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (69 / 78)

Page 80: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Logical Indexing

pr in t ’Mean o f p o s i t i v e s ’ , A[A > 0 ] .mean( )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (70 / 78)

Page 81: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Some Helper Functions

Constructing ArraysA = np . z e ro s ( ( 10 , 10 ) , dtype=np . in t8 )B = np . ones ( 10 )C = np . arange ( 100 ) . reshape ( ( 10 , 10 ) ). . .

Multiple Dimensionsimg = np . z e r o s ( ( 1024 , 1024 , 3 ) , dype=np . u int8 )

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (71 / 78)

Page 82: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Documentation

http://docs.scipy.org/doc/

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (72 / 78)

Page 83: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Last Section

Matplotlib & Spyder

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (73 / 78)

Page 84: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Matplotlib

Matplotlib is a plotting library.Very flexible.Very active project.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (74 / 78)

Page 85: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Example I

import numpy as npimport matp lo t l i b . pyplot as p l tX = np . l i n s p a c e ( - 4 , 4 , 1000 )p l t . p l o t (X, X**2*np . cos (X**2 ) )p l t . s a v e f i g ( ’ s imple . pdf ’ )

y = x2 cos(x2)

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (75 / 78)

Page 86: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Example I

4 3 2 1 0 1 2 3 420

15

10

5

0

5

10

15

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (76 / 78)

Page 87: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Resources

Numpy+scipy docs: http://docs.scipy.orgMatplotlib: http://matplotlib.sf.netPython docs: http://docs.python.org

These slides are available at http://luispedro.org/talks/2012I’m available at [email protected]

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (77 / 78)

Page 88: Introduction to Python - Luis Pedro Coelholuispedro.org/files/talks/2012/lxmls.pdf · Introduction to Python LuisPedroCoelho Institute for Molecular Medicine (Lisbon) LisbonMachineLearningSchoolII

Thank you.

Luis Pedro Coelho (IMM) ⋆ Introduction to Python ⋆ Lisbon Machine Learning School II (78 / 78)