Skip to editor
File
New File Ctrl+N
New Folder

Save Ctrl+S
Upload File…
Download as ZIP

Delete File

Reset Files…
View
Toggle Sidebar Ctrl+B
Toggle Terminal Ctrl+`

Word Wrap Alt+Z

Exercise Info
Run
Run Code Ctrl+Enter
Save & Run F5

Clear Output
CS 477: Module 1: Numpy Exercise (1.5 pts)
Explorer
GitHub

Connect to GitHub to push and pull your project files to a repository.

On the page that opens, create a token with repo scope, copy it, then paste it below.

Paste the personal access token you created on GitHub with repo scope.

Click Refresh to load commit history
Exercise Info

Goals

  1. To apply array indexing in numpy
  2. To use for loops in numpy

Instructions

The code below does one trial (experiment) of the 10 heads in a row game, but that doesn't give us a very good idea of how long it takes in general. We should do the experiment many times to get a better sense. Your task in this exercise is to put the starter code inside of a for loop that loops through num_trials times and stores the number of flips it took for each trial as an element in the trials numpy array. All you should have to do is add a for loop, put all of the code inside, and assign num_flips to an index in trials. Then, we can use the power of matplotlib to plot a histogram showing us a distribution of the number of heads it took over all experiments.



The Ursinus-WebIDE by Chris Tralie (opens in new tab) and Bill Mongan (opens in new tab)

Your browser does not support WebGL. A graphical rendering canvas would appear here.


          
No suggestions. Code quality feedback will appear here.
Not logged in pyodide
Ln 1, Col 1
import io, base64 img_str = "" def save_figure_js(): global img_str buf = io.BytesIO() plt.savefig(buf, format='png') buf.seek(0) img_str = "data:image/png;base64,{}".format(base64.b64encode(buf.read()).decode('UTF-8')) audio_sav_arr = [] audio_sav_sr = 44100 def save_audio_js(arr, sr): global audio_sav_arr global audio_sav_sr audio_sav_arr = np.array(arr).tolist() audio_sav_sr = sr PYODIDE_COUT = "" def pyodide_print(s): global PYODIDE_COUT PYODIDE_COUT += s