Question: PYTHON CLASS *the pictures are in reverse order* Can someone please write the code for the answers to these questions. Thank you! There may be

PYTHON CLASS *the pictures are in reverse order*

Can someone please write the code for the answers to these questions. Thank you!PYTHON CLASS *the pictures are in reverse order* Can someone please writethe code for the answers to these questions. Thank you! There maybe others that you will need. Do the manipulation and computation usingNumPy operations. [] # This code will get you started. import numpyas np array = np.arange (12).reshape(3, 4) print(array) # Test your code

There may be others that you will need. Do the manipulation and computation using NumPy operations. [] # This code will get you started. import numpy as np array = np.arange (12).reshape(3, 4) print(array) # Test your code on the array named array'. [[ 0 [ 4 [8 1 2 3] 5 6 7] 9 10 11]] I also suggest that you use the Python set sequence class. [] Put your code here. # This is test code print(monty (1000, switch-False) > print(monty (1000, switch=True)) (20 pts) For this problem, you are to compute the means across the columns of each row, but in groups of two columns. For example, the first mean is of the first two columns in the first row. The next mean is of the last two columns of the first tow. When done, you should have an array with the same number of rows, but only two columns. You may find the following NumPy functions useful: vstack hatack column_stack TOW stack concatenate split vsplit array_split mean Test code is below. Do not change. [] 1 = [Person(3, "Joe"), Person(2, "Alice"), Person(4, "Mike"), Person(1, "Jane") ] print(1) for ein l: print(e) print(sort(1, less_by_id)) print(sort(l, less_by_name)) [25 pts] For this next problem, write a simulation of the Monty Hall problem. Implement the simulation as a function named monty() that takes two parameters. The first parameter is the number of trials, and the second parameter is whether or not to switch doors after Monty reveals the door containing the goat. A few functions that you may need include: random.randint() random.sample() random.shuffle() I also suggest that you use the Python set sequence class. [3 pts) The cell below will test your sort function. Do not change the code, except for the lambda question. print (sort([5, 4, 3, 2, 1, 1, 2, 6, 7, 8), less_than)) print (sort([5, 4, 3, 2, 1, 1, 2, 6, 7, 8), greater_than)) # For 3 pts, use a lambda to make this sort also sort in descending order, but # using the less than ) comparator. Hint: Change the sign of the return value # of the less_than() comparator. print (sort([5, 4, 3, 2, 1, 1, 2, 6, 7, 8], lambda_goes_here)) (14 pts) Next, you will see how your sort function can be used to sort other types of objects, given appropriate comparator functions. In the cell below, create a Person class. The class should have two, per-instance data attributes, id and name , representing the ID and name of a person, respectively. The class should include a instantiation method named __init_(), which accepts as arguments the ID and name. To make debugging easier, also include a __repr_() method that will return a string to be used for printing. [] # Put your class here. [5 pts] Now implement a less_by_id() function which will compare two Person objects by their ID, and a less_by_name() function which will compare two Person objects by their names. ( # Put your comparison functions here. Test code below. Do not change. There may be others that you will need. Do the manipulation and computation using NumPy operations. [] # This code will get you started. import numpy as np array = np.arange (12).reshape(3, 4) print(array) # Test your code on the array named array'. [[ 0 [ 4 [8 1 2 3] 5 6 7] 9 10 11]] I also suggest that you use the Python set sequence class. [] Put your code here. # This is test code print(monty (1000, switch-False) > print(monty (1000, switch=True)) (20 pts) For this problem, you are to compute the means across the columns of each row, but in groups of two columns. For example, the first mean is of the first two columns in the first row. The next mean is of the last two columns of the first tow. When done, you should have an array with the same number of rows, but only two columns. You may find the following NumPy functions useful: vstack hatack column_stack TOW stack concatenate split vsplit array_split mean Test code is below. Do not change. [] 1 = [Person(3, "Joe"), Person(2, "Alice"), Person(4, "Mike"), Person(1, "Jane") ] print(1) for ein l: print(e) print(sort(1, less_by_id)) print(sort(l, less_by_name)) [25 pts] For this next problem, write a simulation of the Monty Hall problem. Implement the simulation as a function named monty() that takes two parameters. The first parameter is the number of trials, and the second parameter is whether or not to switch doors after Monty reveals the door containing the goat. A few functions that you may need include: random.randint() random.sample() random.shuffle() I also suggest that you use the Python set sequence class. [3 pts) The cell below will test your sort function. Do not change the code, except for the lambda question. print (sort([5, 4, 3, 2, 1, 1, 2, 6, 7, 8), less_than)) print (sort([5, 4, 3, 2, 1, 1, 2, 6, 7, 8), greater_than)) # For 3 pts, use a lambda to make this sort also sort in descending order, but # using the less than ) comparator. Hint: Change the sign of the return value # of the less_than() comparator. print (sort([5, 4, 3, 2, 1, 1, 2, 6, 7, 8], lambda_goes_here)) (14 pts) Next, you will see how your sort function can be used to sort other types of objects, given appropriate comparator functions. In the cell below, create a Person class. The class should have two, per-instance data attributes, id and name , representing the ID and name of a person, respectively. The class should include a instantiation method named __init_(), which accepts as arguments the ID and name. To make debugging easier, also include a __repr_() method that will return a string to be used for printing. [] # Put your class here. [5 pts] Now implement a less_by_id() function which will compare two Person objects by their ID, and a less_by_name() function which will compare two Person objects by their names. ( # Put your comparison functions here. Test code below. Do not change

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!