Question: Question must be done in Python 3.6 If possible, include notes showing where the optional question has been implemented. Also explain why the sorting numbers
Question must be done in Python 3.6
If possible, include notes showing where the "optional" question has been implemented.
Also explain why the "sorting numbers" works.

Sorting numbers Generate a random array. You can use the following code import numpy as np np.random.seed (1000) DATASIZE = 10000 MAX VALUE = 1000000 datanp.random.randint (e, MAX_VALUE, size-DATASIZE) 1. Write a function is passed a numpy array. The function walks through the array element-by-element, comparing the current element to the next element. Swap if the next is smaller than the current - sorting these two elements 2. Write a second function that calls the function from part 1 n times, where n is the number of elements (size) of the array. Pass the same numpy array every time Print the result. Explain to the TA why this sorting function works. Gambling You start the game with S100. The game is . You and the 'dealer' both flip a coin. It costs $1 to play If you flip 'heads', and the dealer flips tails', you win S2 If both you and the dealer flip "heads", you lose, and the dealer takes the S1 If you flip "tails" you lose, and the dealer takes the $1 Run 1000 simulations of games that have 50 flips. You start with $100. What is the average amount of money you end up with? Notes 1. The only loop in your answer is to run 1000 simulations. 2. Use numpy to calculate the mean and standard deviation of the results. Sample output: You ended up with an average of 75.24, standard deviation 5.86 Optional: Sorting data better The sort from part 1 is not optimized. If the data passed to be sorted is alreahy sorted, it still preforms all the work as if the array was not sorted. Change 'function 1' (the one that does all the comparisons) to pass back a boolean that states if the array is now sorted. Further, does 'function 1' have to traverse the entire array every time? Sorting numbers Generate a random array. You can use the following code import numpy as np np.random.seed (1000) DATASIZE = 10000 MAX VALUE = 1000000 datanp.random.randint (e, MAX_VALUE, size-DATASIZE) 1. Write a function is passed a numpy array. The function walks through the array element-by-element, comparing the current element to the next element. Swap if the next is smaller than the current - sorting these two elements 2. Write a second function that calls the function from part 1 n times, where n is the number of elements (size) of the array. Pass the same numpy array every time Print the result. Explain to the TA why this sorting function works. Gambling You start the game with S100. The game is . You and the 'dealer' both flip a coin. It costs $1 to play If you flip 'heads', and the dealer flips tails', you win S2 If both you and the dealer flip "heads", you lose, and the dealer takes the S1 If you flip "tails" you lose, and the dealer takes the $1 Run 1000 simulations of games that have 50 flips. You start with $100. What is the average amount of money you end up with? Notes 1. The only loop in your answer is to run 1000 simulations. 2. Use numpy to calculate the mean and standard deviation of the results. Sample output: You ended up with an average of 75.24, standard deviation 5.86 Optional: Sorting data better The sort from part 1 is not optimized. If the data passed to be sorted is alreahy sorted, it still preforms all the work as if the array was not sorted. Change 'function 1' (the one that does all the comparisons) to pass back a boolean that states if the array is now sorted. Further, does 'function 1' have to traverse the entire array every time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
