
Fix the error
Code:
import numpy as np
from statistics import mean
import matplotlib as plt
import matplotlib.pyplot as plt
from random import randrange
def takeHalfTest(a,b,oper,order):
asOrig=np.random.randint(1,7,a)
if(order==1):
as1=np.sort(asOrig)
else:
as1=-np.sort(-asOrig)
as1=as1[0:b]
out=0
if(oper==1):
out=min(as1)
elif(oper==2):
out=max(as1)
elif(oper==3):
out=mean(as1)
else:
diffs=np.diff(as1)
dMin=np.min(diffs)
j=np.argmin(diffs)
if(dMin<0):
out=j-1
else:
out=b
return out
results = []
n= 10
m= 300
for a1 in range(1,n-1):
for b1 in range(1,a1):
for oper1 in range(1,4):
for order1 in range(1,2):
for a2 in range(1,(n-a1)):
for b2 in range(1,a2):
for oper2 in range(1,4):
for order2 in range(1,2):
counter1=0
counter2=0
for i in range(1,300):
res1= takeHalfTest(a1,b1, oper1,order1)
res2= takeHalfTest(a2,b2, oper2,order2)
if res1 < res2:
counter1= counter1+1
if res1 == res2 :
counter2= counter2+1
# results += [a1,b1,oper1,order1, a2,b2,oper2,order2,1, counter1/m]
# results += [a1,b1,oper1,order1, a2,b2,oper2,order2,2, counter2/m]
results += [counter1/m]
results += [counter2/m]
print(results)
ps = results
f,p = plt.hist(ps,100)
f = f / np.trapz(p,f)
plt.plot(p,f)
grid('on')
plt.xlabel('P(procedure)')
plt.ylabel('freq.')
plt.title('Probabilities of diff. procedures')
The Output of this code is: This is error message while visualizing the data


Step by stepSolved in 3 steps with 1 images

- Heapsort has heapified an array to: 76 62 40 32 30 and is about to start the second for loop. What is the array after each loop iteration? i= 4: Ex: 86, 75, 30 i = 3: i = 2: i= 1:arrow_forwardImplement the following two sorting algorithms in a program called p3.py. Write two separate functions for these algorithms. Both functions must take a list of integers as the input parameter.1) Bogosort: first shuffle the list argument (i.e., randomize the positions of every element) and then check to see if the result is in sorted order. If it is, the algorithm terminates successfully and returns True, but if it is not then the process must be repeated.2) Bozosort: choose two elements in the list at random, swap them, and then check if the result is in sorted order. If it is, the algorithm terminates successfully and returns True, but if it is not then the process must be repeated.Write a main() function and call both sorting functions using the same list as their arguments. The list can be of any size (try a small list first). Does any of your algorithms terminate? If yes, count the number of iterations it uses to sort the list. Does it always use the same number of repetitions? If…arrow_forwardSelect the for-loop which iterates through all even index values of an array.A. for(int idx = 0; idx < length; idx++)B. for(int idx = 0; idx < length; idx%2)C. for(int idx = 0; idx < length; idx+2)D. for(int idx = 0; idx < length; idx=idx+2)arrow_forward
- the below is an example of diabetes dataset import matplotlib.pyplot as pltimport numpy as npfrom sklearn.datasets import load_diabetesfrom sklearn import linear_model d = load_diabetes()d_X = d.data[:, np.newaxis, 2]dx_train = d_X[:-20]dy_train = d.target[:-20]dx_test = d_X[-20:]dy_test = d.target[-20:] lr = linear_model.LinearRegression()lr.fit(dx_train, dy_train) mse = np.mean((lr.predict(dx_test) - dy_test) **2)lr_score = lr.score(dx_test, dy_test) print(lr.coef_)print(mse)print(lr_score)plt.scatter(dx_test, dy_test)plt.plot(dx_test, lr.predict(dx_test), c='r')plt.show()arrow_forwarddef makeRandomList(size): lyst = [] for count in range(size): while True: number = random.randint(1, size) if not number in lyst: lyst.append(number) break return lyst give me proper analysis of this code and Big Oarrow_forwardCan you help me write the code for this one please? Thank youarrow_forward
- Sorting Create a MyLinkedList class with inner Node class, data fields, and the insert(element) method. Implement a toString method to return all nodes in MyLinkedList. Implement a recursive sorting and a non-recursive sorting method.arrow_forwardThe optimised bubble sort offers none of the following benefits over conventional sorts for items that have already been sorted.arrow_forwardDescription: Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1. Example 1 input: "leetcode" output: 0 Example 2 input: "loveleetcode" output: 2 The solution we are targeting here is a linear time solution since we have to go over the entire string to know which one is unique in it. A straightforward method we can easily think of is having a Dictionary record letter frequency. Subsequently, iterate over the input again and return the index that has a letter frequency of 1.arrow_forward
- Python’s list method sort includes the keyword argument reverse, whose defaultvalue is False. The programmer can override this value to sort a list in descendingorder. Modify the selectionSort function so that it allowsthe programmer to supply this additional argument to redirect the sort. selectionSort function: def selectionSort(lyst, profiler):i = 0 while i < len(lyst) - 1:minIndex = ij = i + 1 while j < len(lyst):profiler.comparison() # Countif lyst[j] < lyst[minIndex]:minIndex = jj += 1 if minIndex != i:swap(lyst, minIndex, i, profiler)i += 1 def swap(lyst, i, j, profiler):"""Exchanges the elements at positions i and j."""profiler.exchange() # Counttemp = lyst[i]lyst[i] = lyst[j]lyst[j] = temp Use this template in Python to modify the function above: def selection_sort(input_list, reverse):sorted_list = []#TODO: Your work here# Return sorted_listreturn sorted_listif __name__ == "__main__":my_list = [1, 2, 3, 4, 5]print(selection_sort(my_list, True)) # Correct Output: [5,…arrow_forwardEdit the given Python Code (about Probability) so it can do the Additional Task. Please see the attached pics to complete it. Code that Needs to be Edited:from collections import Counterfrom scipy.stats import binom# Part A: Find the 7 most common repetitive numbers number_list = [25, 23, 17, 25, 48, 34, 29, 34, 38, 42, 30, 50, 58, 36, 39, 28, 27, 35, 30, 34, 46, 46, 39, 51, 46, 75, 66, 20, 45, 28, 35, 41, 43, 56, 37, 38, 50, 52, 33, 44, 37, 72, 47, 20, 80, 52, 38, 44, 39, 49, 50, 56, 62, 42, 54, 59, 35, 35, 32, 31, 37, 43, 48, 47, 38, 71, 56, 53, 51, 25, 36, 54, 47, 71, 53, 59, 41, 42, 57, 50, 38, 31, 27, 33, 26, 40, 42, 31, 25, 26, 47, 26, 37, 42, 15, 60, 40, 43, 48, 30, 25, 52, 28, 41, 40, 34, 28, 40, 38, 40, 30, 35, 27, 27, 32, 44, 31, 32, 29, 31, 25, 21, 23, 25, 39, 33, 21, 36, 21, 14, 23, 33, 27, 31, 16, 23, 21, 13, 20, 40, 13, 27, 33, 34, 31, 13, 40, 58, 24, 24, 17, 18, 18, 21, 18, 16, 24, 15, 18, 33, 21, 13, 24, 21, 29, 31, 26, 18, 23, 22, 21, 32, 33, 24, 30, 30, 21, 23, 29,…arrow_forwardJavaarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





