Assignment 5 Feedback

Closed at 2pm Monday 13th; I can't accept late submissions unfortunately.

People's coding is getting better, fewer mistakes. Higher scores.

Please contact me if you can't see a scored feedback for a assignment (1 - 5) as this is what is recorded in the database!

Send me additional emails if I don't respond; like a giant stack of pancakes I'm often dealing with the latest one.

Good news, there is a link to click at the top of the Assignment 6 notebook.

This is a 100% scoring example.

What is wrong here?

What is wrong here?

What is wrong here?

What is wrong here?

What is wrong here?

This is a 100% scoring example.

What is wrong here?

Array Indexing

Say our numpy array looks like this:

A B C

A B C

A B C

  • How can we apply a function to all of the rows or columns?

Array Indexing

    # Create array of zeros
    x = np.ones((3,4))
    # [[1. 1. 1. 1.]
       [1. 1. 1. 1.]
       [1. 1. 1. 1.]]

    # sum over rows
    y = np.sum(x, axis=0)
    # [3. 3. 3. 3.]

    # sum over columns
    z = np.sum(x, axis=1)
    # [4. 4. 4]
                      

Broadcasting

        # Create array of zeros
        x = np.ones((3,4))
        # [[1. 1. 1. 1.]
           [1. 1. 1. 1.]
           [1. 1. 1. 1.]]
    
        y = x + 5        
                            

What is going to happen to this array?

Broadcasting

      # y
      # [[6., 6., 6., 6.],
         [6., 6., 6., 6.],
         [6., 6., 6., 6.]]
        
                          

Broadcasting

    # Create array of zeros
    x = np.ones((3,4))
    # [[1. 1. 1. 1.]
       [1. 1. 1. 1.]
       [1. 1. 1. 1.]]

    y = (x + 2) * (x + 2)       
                        

What is going to happen to this array?

Broadcasting

  # y
  # [[9. 9. 9. 9.]
     [9. 9. 9. 9.]
     [9. 9. 9. 9.]]