Question: python 3.7 code: Exercise 1: Sorting Generate a random array. You can use the following code import numpy as np np.random.seed(1012) DATASIZE = 10000 MAX_VALUE

python 3.7 code:

Exercise 1: Sorting


Generate a random array. You can use the following code


import numpy as np np.random.seed(1012) DATASIZE = 10000 MAX_VALUE = 1000000000 data = np.random.randint(0, MAX_VALUE, size=DATASIZE)


Write a function that 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.


Write a second function that calls the function from part 1 nn times, where nn 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.


Lab 9 Week of November 4 Material covered: Numpy arrays Functions Simulations Complete either exercise 1, or exercise 2. Exercise 1: Sorting Generate a random array. You can use the following code import numpy as np np.random. seed (1012) D DATASIZE = 10000 MAX_VALUE= 1000000000 data = np.random.randint (0, MAX VALUE, size=DATASIZE) tent/1719967/View 80% *** 1. Write a function that 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.

Step by Step Solution

3.47 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer HI the complete code is as bellow import numpy as np npran... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!