Skip to main content

Lab 1: Math Review & Numpy

Objectives:

The main goals for this lab are:

  1. Start getting familiar with numpy.
  2. Brush up on relevant math (Linear Algebra, Calculus, Probabiltiy).

Make sure to write down your answers below. In future labs, the TAs or Instructor will check your answers. Whenever you see TODO, that means there is an action item for you to complete.

1. Python Introduction (Optional)

From the terminal, you can start a python interpreter by just typing python in the command-line. Once you create a python, you can run it from terminal by just running python <filename>.py.

If you are new to python, go through at least the following sections of this Python tutorial:

2. Numpy Introduction

Some steps below are borrowed from numpy quickstart tutorial, which I encourage you to reference throughout the course.

During this course we will often use numpy to manage our datasets. Type the following commands in the python interpreter (filling in missing pieces) and make sure the output makes sense:

Array creation and modification

python
>>> import numpy as np
>>>
>>> # create a 4x5 array of zeros
>>> m = np.zeros([4,5])
>>> m
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>>
>>> # create a 3x5 array of zeros using reshape
>>> a = np.arange(15).reshape(3, 5)
>>> a
array([[ 0,  1,  2,  3,  4],
      [ 5,  6,  7,  8,  9],
      [10, 11, 12, 13, 14]])
>>>
>>> # create an array from a list
>>> b = np.array([6, 7, 8])
>>> b
array([6, 7, 8])

TODO and DISCUSS




Switch who is navigator and driver

Array slicing and concatenation

Try out the slicing operations below, predicting what will be printed each time. Make sure you have modified the m array enough that output is clear (you may need to recreate m if you switched who was sharing the screen).

>>> m[2]
>>> m[:,1]
>>> m[:3,:2]

TODO and DISCUSS

optional: save your interpreter commands to a file and email to each partner




3. Math Pre-exam

Complete the following math pre-exam. This will be graded on effort, not correctness - the purpose of this part of Lab 1 is so that I know how much math review to do later on. You have a few options for working on this part:

  1. Print it out, write down your answers on the pages.
  2. Write your answers on a separate sheet of paper, but clearly number the questions.
  3. LaTeX your answers.
  4. For the first two approaches, “scan” the pages using a phone (I recommend the app “CamScanner”) to create a single PDF. For all approaches, add the final PDF to your Lab 1 on Gradescope.

This part of the lab should be submitted individually.

Signing out

For the remaining labs, before leaving, make sure your TA/instructor have signed you out of the lab. If you finish the lab early, you are free to go.