CS5800: Introduction
Dr. Anand Subramoney
Royal Holloway, University of London
1
Who am I
✓ Leader: Dr. Anand Subramoney
✓ [Link]@[Link]
✓ I use the pronouns he/his/him
✓ Please call me Anand, but Prof if you’re uncomfortable with that
✓ I’ll call you by your first name, but let me know if you want me
to use something different.
✓ Office hours: Mondays 15-16, Wednesdays 10-11
◦ You can drop by my office without an appointment during these
times.
◦ Office: McCrea 0-24
2
Structure
✓ Most teaching in first five weeks
✓ Two hour lecture every week
◦ Wednesday 14:00 HORTON HLT2
✓ Two hour lab every week
◦ Wednesday 16:00 BEDFORD LABS
✓ Slows down after that
✓ Two in-class tests!
3
Labs
✓ Document of tasks to complete.
✓ Based on materials delivered.
✓ Can use lab PC’s or your own laptop.
✓ Recommend you install Spyder on your laptop.
✓ Use lab time to talk technical issues
✓ Both me and a TA will be present during the labs
✓ Lab TA: Vasudha Darbari
4
Assessment
✓ Summative tests - 2 tests @ 10%, 10%
◦ Up to 60 minutes.
◦ 10 questions randomly selected from a question bank.
✓ Final exam - 80%
5
Tools
✓ Moodle
[Link]
✓ NoMachine
✓ Python and Spyder.
6
Moodle
✓ Virtual Learning Environment (VLE).
✓ All materials, quizzes, links to items of interest go there.
✓ Forum to ask questions
◦ Can be asked anonymously.
✓ Ask your questions in the Forums first outside of Lab hours!
7
NoMachine
✓ Tool that allows you to log into the CS RHUL servers from your
laptop.
✓ You do not have to install Python etc. on your own laptop
(though it makes life easier).
8
Python
✓ This module teaches you Python.
◦ [Link] - for installation.
✓ Spyder is an Integrated Development Environment (IDE) for
Python (installed by default with anaconda)
9
What is python
✓ Python is a modern, general-purpose, object-oriented, high-level
programming language.
✓ From the python website:
◦ "Python is an easy to learn, powerful programming language. It has
efficient high-level data structures and a simple but effective
approach to object-oriented programming. Python’s elegant syntax
and dynamic typing, together with its interpreted nature, make it an
ideal language for scripting and rapid application development in
many areas on most platforms."
10
What is python
✓ General characteristics of Python:
◦ clean and simple language: Easy-to-read and intuitive code, easy-to-learn minimalistic
syntax, maintainability scales well with size of projects.
◦ expressive language: Fewer lines of code, fewer bugs, easier to maintain.
✓ Technical details:
◦ dynamically typed: No need to define the type of variables, function arguments or
return types.
◦ automatic memory management: No need to explicitly allocate and deallocate memory
for variables and data arrays. No memory leak bugs.
◦ interpreted: No need to compile the code. The Python interpreter reads and executes
the python code directly.
1
1
Why python?
✓ Open-source language that works everywhere (including the Raspberry
Pi!)
✓ Extensive ecosystem of scientific libraries and environments
✓ Great performance due to close integration with time-tested and highly
optimised libraries written in C and Fortran
✓ Good support for Parallel processing, GPU computing etc.
✓ It’s the defacto programming language for machine learning
(Tensorflow, PyTorch, JAX…)
✓ Also very good for GUI, servers, scripting etc.
12
Engagement
✓ You need to stay on top of this material.
✓ Watch the videos.
✓ Attend labs.
✓ Attend the live events.
✓ Most students taking distance learning modules fail because
they don’t stick with it.
13
Entrance quiz
✓ If you are taking Data Science and Analytics MSc then this is a
core module.
✓ Entrance quiz check to see if you already are good enough at
Python.
✓ Will be open soon, and will be open until Oct. 8th
✓ You can use it to evaluate if you know enough Python to skip the
course.
◦ Get at least 70%
✓ BUT, you can still skip this course even if you don’t pass. BUT
THIS IS NOT RECOMMENDED.
14
Learning objectives
1. Understand standard programming concepts.
2. Apply understanding to solve programming tasks.
3. Evaluate programming solutions.
15
More practically
✓ You learn basic Python.
✓ You learn some basic principles of Computer Science.
✓ Enough to get you ready to do some Data Science.
16
In more detail
1. Introduction 4. Functions, tuples, lists
a. Languages, types, variables a. Functions, abstraction,
decomposition, reuse
b. The python console
b. functions in Python; variable
2. Control flow scope, functions as
a. Basic types in Python arguments, visibility
b. Comparison operations 5. Tuples, lists
c. Branching a. Tuples; defining,
d. while, for loops immutability, unpacking,
operations
e. break statement
b. Lists; defining, mutability,
3. Strings, simple algos indexing, iterating, operations
a. String indexing and slicing c. Multi-dimensional arrays
b. string mutability
17
In more detail (II)
6. Dictionaries 8. OOP 1
a. keys, values a. OOP concepts
b. Operations b. Creation, destruction
c. Iterating c. Class attributes, methods
7. Files, Pandas, Numpy d. Querying types
a. File I/O e. Special methods
b. Pandas basics
c. NumPy arrays and operations 9. OOP 2
a. Why use objects?
b. getter and setter methods
c. information hiding
d. hierarchies, inheritance
e. Class variables
18
Applicability
✓ If you have
◦ No prior experience in programming
◦ You had a little experience in programming
✓ Then this is the module for you.
19
Course Info: Resources
✓ MIT Course: Introduction to Computer Science and Programming in Python
◦ [Link]
0001-introduction-to-computer-science-and-programming-in-python-fall-
2016/[Link]
✓ edX course: [Link]
v1:MITx+6.00.1x+2T2018/course/
✓ John Guttag. Introduction to Computation and Programming Using Python:
With Application to Understanding Data Second Edition. MIT Press, 2016.
ISBN: 9780262529624
✓ Zed Shaw, Learn Python the hard way, 5th Ed., Pearson Addison Wesley,
2024. ISBN: 9780138270575
✓ Numerous other online resources (watch Moodle space and library reading
list)
20
Fast-paced course
✓ New to programming? PRACTICE. PRACTICE? PRACTICE!
◦ Work hard at lab sessions
◦ Try things on your own
◦ Get into habit of using Python for your everyday problem solving
21
Problem
Solving
PRACTICE
Knowledge of Programming
Concepts Skills
2
2
Introduction (computers)
What does a computer do?
✓ Fundamentally:
◦ performs operations -> calculations
a billion calculations per second!
◦ remembers results (100s of gigabytes of storage!)
✓ What kinds of calculations?
◦ built-in to the language
◦ ones that you define as the programmer
✓ Computers only know what you tell them
24
The one trick of Computer Science
✓ Create a set of primitive “things”.
✓ Have a set of simple rules for those “things” to be put together.
✓ Build arbitrarily complex things from the primitive things.
25
TYPES OF KNOWLEDGE
✓ Declarative knowledge is statements of facts
◦ There is a student in the 2nd row whose name is …
✓ Imperative knowledge is a recipe or “how-to”
1. Face the students at the front of the room
2. Count up 2 rows
3. Start from the student in the leftmost chair
4. Ask the student to tell their name
5. If not … count to the right 1 chair, goto 4
6. Otherwise, report the chair where … was found
7. Terminate
26
Numerical Example
✓ Square root of a number x is y such that y*y = x
✓ Recipe for deducing square root of a number x (16)
◦ Start with a guess, g
◦ If g*g is close enough to x, stop and say g is the answer
◦ Otherwise make a new guess by averaging g and x/g
◦ Using the new guess, repeat process until close enough
g g*g x/g (g+x/g)/2
3 9 16/3 4.17
4.17 17.36 3.837 4.0035
4.0035 16.0277 3.997 4.000002
27
What is a recipe?
1. Sequence of simple steps
2. Flow of control process that specifies when each step is
executed
3. A means of determining when to stop
1 + 2 + 3 = an algorithm!
28
Basic Machine Architecture
29
Stored Program Computer
✓ Sequence of instructions stored inside computer
◦ Built from predefined set of primitive instructions
• arithmetic and logic
• simple tests
• moving data
✓ Special program (interpreter) executes each instruction in order
◦ Use tests to change flow of control through sequence
◦ Stop when done
30
Creating Recipes
✓ A programming language provides a set of primitive operations
✓ Expressions are complex but legal combinations of primitives in
a programming language
✓ Expressions and computations have values and meanings in a
programming language
31
Aspects of Languages
✓ primitive constructs
◦ English: words
◦ programming language: numbers, strings, simple operators
32
Aspects of Language
✓ Syntax
◦ English: "cat dog boy" ➔ not syntactically valid
"cat hugs boy" ➔ syntactically valid
◦ programming language:
"hi"5 ➔ not syntactically valid
3.2*5 ➔ syntactically valid
33
Aspects of Languages
✓ static semantics is which syntactically valid strings have
meaning
◦ English: “I are hungry” → syntactically valid but static semantic
error
◦ Programming language:
• 3.2*5 → syntactically valid
• 3+"hi" → static semantic error
34
Aspects of Languages
✓ Semantics is the meaning associated with a syntactically correct
string of symbols with no static semantic errors
◦ English: can have many meanings "Flying planes can be
dangerous"
◦ programming languages: have only one meaning but may not be
what programmer intended
35
Where things go wrong
✓ Syntactic errors
◦ common and easily caught
✓ Static semantic errors
◦ some languages check for these before running program
◦ can cause unpredictable behaviour
✓ No semantic errors but different meaning than what programmer
intended
◦ program crashes, stops running
◦ program runs forever
◦ program gives an answer but different than expected
36