Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago