Day 4 pre-class assignment

Goals for today's pre-class assignment

  • Use the pyplot module to make a figure
  • Use the NumPy module to manipulate arrays of data

Assignment instructions

Watch the videos below, do the readings linked to below the videos, and complete the assigned programming problems. Please get started early, and come to office hours if you have any questions!

Recall that to make notebook cells that have Python code in them do something, hold down the 'shift' key and then press the 'enter' key (you'll have to do this to get the YouTube videos to run). To edit a cell (to add answers, for example) you double-click on the cell, add your text, and then enter it by holding down 'shift' and pressing 'enter'

This assignment is due by 11:59 p.m. the day before class, and should be uploaded into the "Pre-class assignments" dropbox folder for Day 4. Submission instructions can be found at the end of the notebook.

IPython tutorial -- this contains some very useful suggestions about IPython commands that allow you to get help on Python, figure out what specific variables or objects do, and many other things.

Jupyter notebook tips and tricks -- some clever things you can do with Jupyter notebooks

Another Jupyter notebook tip page


In [ ]:
# Imports the functionality that we need to display YouTube videos in a Jupyter Notebook.  
# You need to run this cell before you run ANY of the YouTube videos.

from IPython.display import YouTubeVideo

In [ ]:
# Display a specific YouTube video, with a given width and height.  
# WE STRONGLY RECOMMEND that you can watch the video in full-screen mode
# (much higher resolution) by clicking the little box in the bottom-right 
# corner of the video.

YouTubeVideo("chBLLNBGoEE",width=640,height=360)  # modules and pyplot

Useful references:

Question 1: The cell below contains four lists of data, which correspond to two sets of X and Y values. Use matplotlib to make a plot of these datasets. The first pair of lists (x1, y1) should be drawn with a thick blue dashed line and the second pair of lists (x2, y2) should be drawn with red diamonds. Make the width and height of the plot a bit wider than the region occupied by the points, so that you can see the shape that is drawn. Add axis labels to the x and y axes, with whatever text you like. Use the Pyplot Tutorial for inspiration, and in particular you can find instructions on how to create different types of characters and line types in the pyplot 'plot' command documentation.


In [ ]:
# imports the pyplot module from matplotlib
import matplotlib.pyplot as plt    

# ensures that the plots made by matplotlib/pyplot show up in the notebook!
%matplotlib inline                 

x1 = [2,4,6,8,10,12,14,16,18]
y1 = [10,8.25,7.5,7,6.5,7,7.5,8.25,10]

x2 = [5, 15]
y2 = [15, 15]

# put your plotting commands here!

In [ ]:
# Display a specific YouTube video, with a given width and height.  
# WE STRONGLY RECOMMEND that you can watch the video in full-screen mode
# (much higher resolution) by clicking the little box in the bottom-right 
# corner of the video.

YouTubeVideo("BTXyE3KLIOs",width=640,height=360)  # numpy

Question 2: In the cell below, import the numpy module and then create two arrays with the same number of elements in each one (pick the number of elements and the value of each yourself, making sure they're numbers and not strings!). Then, add those arrays together and store it in a third array, and print it out. Sort the values of the third array, and print that out again.


In [ ]:
# put your code here!

Assignment wrapup

Question 3: What questions do you have, if any, about any of the topics discussed in this assignment after watching the videos, reading the links, and trying to write the programs?

Put your answer here!

Question 4: Do you have any further questions or comments about this material, or anything else that's going on in class?

Put your answer here!

Question 5: Approximately how long did it take you to finish this assignment?

Put your answer here!

Congratulations, you're done!

Submit this assignment by uploading it to the course Desire2Learn web page. Go to the "Pre-class assignments" folder, find the dropbox link for Day 3, and upload it there.

See you in class!


In [ ]: