ML One
Lecture 04
Introduction to scalar, vector and matrix
+
Python and Colab notebook basics 101
Welcome ๐Ÿ‘ฉโ€๐ŸŽค๐Ÿง‘โ€๐ŸŽค๐Ÿ‘จโ€๐ŸŽค
By the end of this lecture, we'll have learnt about:
The theoretical:
- A gentle introduction to scalar, vector and matrix
The practical:
- A gentle introduction to Google colab notebook
- Python basics 01
First of all, don't forget to confirm your attendence on Seats App!
A mockumentary made with AI
Recap
Numeric representation ๐ŸŒถ๏ธ
- How do we use numbers to represent image, audio and text
- The output from an image classification model: the image classes.
- We can use one-hot encoding to represent image classes.
generated by stable diffusion: โ€œa screenshot of an ios face detector appโ€
Numeric representation ๐ŸŒถ๏ธ
- The output from face detection models: bounding boxes and/or landmarks.
- We can use coordinates to represent the location of a point within an image.
- We can use the combination of [the coordinates of a chosen corner, its width, its height] to represent the location of a rectangle within an image.
Today we are going to see numeric representations not on the white board, but on our computers in action!
scalar, vector, matrix big picture:
- different ways to organise numbers
- cater for different data modalities
Why do we need them?
- We have to use numbers to represent stuff and one single number is often not enough.
- There are usually many numbers hence it is inevitable to look at how these numbers are organised.
Scalar:
one single number
Morning noodling time!
๐ŸŒถ๏ธ Q1: Example of data being a scalar? ๐ŸŒค
Vector:
- can be thought of as a list of numbers
- can be in a row or column
- The number of elements in a vector is called its length or, sometimes, its width.
Noodling time!
๐ŸŒถ๏ธ Q2: Example of data being a vector? ๐ŸŒค๐Ÿ”ˆ
Noodling time!
๐ŸŒถ๏ธ Q2.5: How about that dog-or-cat one-hot class label?
Matrix
- can be thought of as an array of numbers
- or a list of vectors (with the same length)
Noodling time!
๐ŸŒถ๏ธ Q3: Example of data being a matrix? ๐Ÿฉป
The shape of a matrix
- # of rows x # of columns
- (on whiteboard)
๐ŸŒถ๏ธ๐ŸŒถ๏ธ Q4: What's the shape of this matrix?
2 x 3
Vector can be seen as a special case of matrix,
and we can describe the shape of a vector the same as matrix:
- K rows x 1 columns ๐Ÿ˜€
- (let's draw a column vector on the whiteboard)
- or 1 rows x K columns ๐Ÿ˜€
- (let's draw a row vector on the whiteboard)
Till now we have looked at:
- scalar, vector and matrix
- how to describe their shapes
- how many rows x how many columns
- the convention is to put the number of rows in the front
Next:
- Let's do some simple math operation!
Add two scalars together:
easy, just add!
Add two matrices together:
easy, just add!
but they have to be of the exactly same shape!
๐ŸŒถ๏ธ๐ŸŒถ๏ธWhat if I want to add a matrix of 2x3 and a matrix of 3x2 together?
๐ŸŒถ๏ธ๐ŸŒถ๏ธWhat if I want to add a matrix of 2x3 and a matrix of 3x2 together?
- Nope I can't, because it is not defined. ๐Ÿ˜ค
Another video made with AI
Next, we are going to:
- take our first look at the google colab notebook!
- learn some very simple python basics!
- see how scalar, vector and matrix are used in python
A prepared google colab notebook
1. click on the link and open this google colab notebook
2. Open it in playground or save a copy to your google drive (recommended)
Demystify google colab notebook
Two types of cells โœŒ๏ธ
- Text cell
-- It is for passing information to other people reading the notebook.
-- just like comment in swift, but with better layout.
- Code cell:
-- It is the actual programming part.
-- It has a play button at the top left corner. โ–ถ๏ธ
Without explaining what the code is doing, here is a screenshot of a code cell and its output
How would you distinguish a code cell from a text cell?
How would you distinguish a code cell from a text cell?
- Code cells have grey-ish background.
- Code cells have run buttons at the top left corner when you hover over.
Let's take a look at the notebook!

- 1. Make sure you have saved a copy to your GDrive or opened in playground.
- 2. Read all text cells and code cells one by one.
- 3. Run all code cells and don't forget to read the comments in code cells.
- 4. Ignore stuff after the text "This is the end of week 4"
Little tasks ๐ŸŒถ๏ธ๐ŸŒถ๏ธ:
- Add a text cell at the beginning of notebook and write down your name and your mood of the day ๐Ÿ˜ˆ
- Add a code cell below that text cell and write two lines of code:
-- 1. Create a variable named "greetings" and assign a string value "bello" to it
-- 2. Print the variable greetings using print(greetings)
-- 3. Run the cell!!!
That's quite a lot, congrats! ๐ŸŽ‰
Now let's advance to the next notebook with python basics 01
- Let's take a look at the notebook cell-by-cell till "Functions (week 5)"
- Don't forget to make a copy to your GDirve ๐ŸŽ‰
- We are not expected to memorise the syntax.
- The goal is to familiarise ourselves with the concept of:
-- basic arithmetic in python ๐Ÿงฎ
-- lists in python ๐Ÿงบ
-- strings in python ๐Ÿ”ค
-- conditionals in python โ“
-- loops in python ๐ŸŒ€
Finally the main theme:
- scalar, vector and matrix in Python
-- we will use a very popular library called "NumPy" to help us handling vectors and matrices.
-- Take away message: In NumPy, all vectors and matrices are wrapped in NumPy "arrays" !
- Let's take a look at the notebook cell-by-cell:
- From "Numpy" to "Reshape NumPy arrays (week 5)"
- We are not expected to memorise the syntax.
- The goal is to familiarise ourselves with the concept of:
-- how to create numpy arrays using python lists ๐Ÿงš
-- how to check the shape of a numpy array ๐Ÿ’ 
-- how to add two arrays together โž•
-- how images and audios are represented using numpy arrays in action ๐Ÿ“ข
-- You are welcome to take notes of unfamiliar notions/syntax and search for explanations (either from the internet or us)
Till now we have looked at:
- How to use google colab notebook
- Python basics:
-- variables, print method, lists, stringsm conditionals, loop
- NumPy
-- vector and matrix as Numpy arrays
-- shapes of Numpy arrays
-- add two Numpy arrays
-- can confirm: images and audios can live in the matrix
That's quite a lot, congrats! ๐ŸŽ‰
An example of running fun "niche" AI models using colab notebook:
a text-to-3D model called dreamfield
- Have you seen the "Open in Colab" button?
Let's play with the dreamfield Colab notebook
a text-to-3D model called dreamfield
- 1. Open the notebook by clicking the "Open in Colab" button in the readme section.
- 2. Run all the code cells except the marked "optional" ones.
- 3. Some cells take a long time to run and you can expand the cell to see what it is doing.
- 4. Prompt_text under "Training Settings" is where you can type in your own prompt.
- 4.5. Maybe enter a small value of Epoch_num under "Training Settings" if you are in a hurry.
- 5. If you have entered a new prompt, make sure you run the following code cells again to get the updated results.
Today we have looked at:
Scalar, vector and matrix ๐Ÿง‘โ€๐ŸŽจ
- how to describe their shapes
-- how many rows x how many columns
-- how to add two matrices of the exactly same shape
Google colab notebook ๐Ÿ“˜
- Text cell and Code cell
Python basics ๐Ÿ
- variables, print method, lists, stringsm conditionals, loop
- vector and matrix in Numpy NumPy ๐Ÿงฎ
- vector and matrix as Numpy arrays
- shapes of Numpy arrays
- add two Numpy arrays
We'll see you next Thursday same time and same place!