lab05.pdf - lab05 October 8, 2018 1 Lab 5: Simulations...

• Lab Report
• 33
• 97% (101) 98 out of 101 people found this document helpful

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

The preview shows page 3 - 4 out of 33 pages.
lab05October 8, 20181Lab 5: SimulationsWelcome to Lab 5!We will go overiteration and simulations, as well as introduce the concept ofrandomness.The data used in this lab will contain salary data and other statistics for basketball playersfrom the 2014-2015 NBA season. This data was collected from the following sports analytic sites:Basketball ReferenceandSpotrac.First, set up the tests and imports by running the cell below.In [2]:# 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.pyplotasplotsplots.style.use('fivethirtyeight')# Don't change this cell; just run it.fromclient.api.notebookimportNotebookok=Notebook('lab05.ok')_=ok.auth(inline=True)=====================================================================Assignment: SimulationsOK, version v1.12.5=====================================================================Successfully logged in as [email protected]1.11. Nachos and ConditionalsIn Python, Boolean values can either beTrueorFalse. We get Boolean values when using com-parison operators such as<(less than),>(greater than), and==(equal to).A list of commoncomparison operators can be found below!1
Run the cell below to see an example of a comparison operator in action.
Arrays are compatible with comparison operators. The output is an array of boolean values.In [5]:make_array(1,5,7,8,3,-1)> 3Out[5]:array([False,True,True,True, False, False])One day, when you come home after a long week, you see a hot bowl of nachos waiting onthe 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’stryandsimulatetakingnachosfromthebowlatrandomusingthefunction,np.random.choice(arr), wherearris the array that you’re using. Start by running the cell belowseveral times, and observe how the results change.
Question 1.Assume we took ten nachos at random, and stored the results in an array calledten_nachosas done below. Find the number of nachos with only cheese using code (do not hard-code the answer).Hint:Our solution involves a comparison operator and thenp.count_nonzeromethod.
2
Conditional StatementsA conditional statement is composed of a sequence of conditions that allow Python to choosefrom different alternatives based on whether some condition is true.

Course Hero member to access this document

Course Hero member to access this document

End of preview. Want to read all 33 pages?