Assignment 3

Closed at 2pm Monday 30th; can't accept late submissions the results were collected then and whatever was submitted was marked

Remember

  1. The autograder will look at your most recent submission.
  2. If there are errors when you 'restart and run all' on your notebook these will appear on the autograder also.
  3. The autograder specifically searches for a notebook titled 'Assignment 3' for grading purposes. Renaming the notebook to something else, like 'my submission,' will result in it being overlooked by the autograder.
  4. Writing code that installs packages on your notebook will disrupt the autograding process. All the packages you need should already be installed. If you believe you need a specific package, please contact me about it.

Apologies if this is harsh but can't go on with ~5% late every week.

If I don't respond to an email please follow up but remember I need your CIS username!!!

Assignment 3 Feedback

I understand that the assignments can be quite challenging but the scores are very good (85% average) so typically you are 'getting it in the end'.

We're moving onto a new subject today so the 'find a point and shuffle along' methods are finishing; if you never felt you never 'got it' we're starting something new now so I want to lead with concept first .

For plagiarism (from last week), I'm accumulating evidence - be warned.

Lets go through a few examples of what people got wrong with the plots:

This is a 100% scoring example.

What is wrong here?

What is wrong here?

What is wrong here?

What is wrong here?

NumPy Arrays

Ways to Create NumPy Arrays:

  • From Python Lists using numpy.array()
  • Zeros Array using numpy.zeros()
  • Ones Array using numpy.ones()
  import numpy as np
  
  # From Python Lists
  a = np.array([1, 2, 3]) 
  
  # Zeros Array
  b = np.zeros((3,100))
  c = np.zeros((10,4))
  
  # Ones Array
  d = np.ones((40,4,1000))
  
                        

Array Indexing

Say our numpy array looks like this:

A B C

A B C

A B C

  • How can we select the first 'A,B,C'

Array Indexing

Selecting Subarrays:

  • Selecting rows using array[row, :]
    # Assume x is a 3x100 array of zeros
    x = np.zeros((3,100))
    
    # Selecting the first row of b
    first_row_x = x[0, :]
    
    # Output [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0.]
    
                          

Array Indexing

Say our numpy array looks like this:

A B C

A B C

A B C

  • How can we select all the 'A's

Array Indexing

Selecting Subarrays:

  • Selecting columns using array[:, column]
      # Assume x is a 10x4 array of zeros
      x = np.zeros((10,4))
      
      # Selecting the first column of c
      first_col_x = x[:, 0]

      # Output: [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
      
                            

Array Functions

Applying Functions to Arrays:

  • Element-wise function application with numpy functions
import numpy as np

# Array of ones with a small value
e = np.ones((3,4)) * 0.1

# Applying the natural logarithm to each element of e
log_e = np.log(e)