lab5 - lab05_master 2/24/19, 11(55 PM Lab 5: Simulations ¶...

This preview shows page 1 - 4 out of 34 pages.

The preview shows page 3 - 4 out of 34 pages.
2/24/19, 11(55 PMlab05_masterPage 1 of 34Lab 5: SimulationsWelcome to Lab 5!We will go overiteration()andsimulations(), as well as introduce the concept ofrandomness().The data used in this lab will contain salary data and other statistics for basketball players from the 2014-2015 NBA season. This data was collected from the following sports analytic sites:Basketball Reference()andSpotrac().First, set up the tests and imports by running the cell below.In [1]:# Run this cell, but please don't change it.# These lines import the Numpy and Datascience modules.importnumpyasnpfromdatascienceimport*# These lines do some fancy plotting magicimportmatplotlib%matplotlibinlineimportmatplotlib.pyplotaspltplt.style.use('fivethirtyeight')# Don't change this cell; just run it.fromclient.api.notebookimportNotebookok=Notebook('lab05.ok')1. Nachos and Conditionals=====================================================================Assignment: SimulationsOK, version v1.12.5=====================================================================
2/24/19, 11(55 PMlab05_masterIn Python, the boolean data type contains only two unique values:TrueandFalse. Expressionscontaining comparison operators such as<(less than),>(greater than), and==(equal to) evaluate toBoolean values. A list of common comparison operators can be found below!Run the cell below to see an example of a comparison operator in action.In [2]:3 > 1 + 1We can even assign the result of a comparison operation to a variable.In [3]:result= 10 / 2 == 5resultOut[2]:TrueOut[3]:
Page 2 of 34Arrays are compatible with comparison operators. The output is an array of boolean values.In [4]:make_array(1,5,7,8,3,-1One day, when you come home after a long week, you see a hot bowl of nachos waiting on the dining table!Let's say that whenever you take a nacho from the bowl, it will either have onlycheese, onlysalsa,bothcheese and salsa, orneithercheese nor salsa (a sad tortilla chip indeed).Let's try and simulate taking nachos from the bowl at random using the function,np.random.choice(...).np.random.choicenp.random.choicepicks one item at random from the given array. It is equally likely to pick any of theitems. Run the cell below several times, and observe how the results change.Out[4]:array([False,True,True,True, False, False]))> 3
2/24/19, 11(55 PMlab05_master)
Page 3 of 34

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 34 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
Pride and Prejudice, Simple random sample

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture