100%(21)21 out of 21 people found this document helpful
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: Simulations¶Welcome 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 :# 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 :3 > 1 + 1We can even assign the result of a comparison operation to a variable.In :result= 10 / 2 == 5resultOut:TrueOut:
Get answer to your question and much more
Page 2 of 34Arrays are compatible with comparison operators. The output is an array of boolean values.In :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:array([False,True,True,True, False, False]))> 3