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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

ValueError
Traceback (most
<ipython-input-38-6844d7b53025> in <module>
36
37 ps results
---> 38 f₂p = plt.hist(ps, 100)
39 f f/np.trapz (p, f)
40 plt.plot(p, f)
ValueError: too many values to unpack (expected 2)
Transcribed Image Text:ValueError Traceback (most <ipython-input-38-6844d7b53025> in <module> 36 37 ps results ---> 38 f₂p = plt.hist(ps, 100) 39 f f/np.trapz (p, f) 40 plt.plot(p, f) ValueError: too many values to unpack (expected 2)
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Mergesort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education