1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
WITCHER [35]
2 years ago
7

Write a function sample_median(n,P) that generates n random values using distribution P and returns the median of the collected

sample. Hint: Use function random.choice() to sample data from P and median() to find the median of the samples * Sample run * print(sample_median(10,[0.1 0.2 0.1 0.3 0.1 0.2])) print(sample_median(10,[0.1 0.2 0.1 0.3 0.1 0.2])) print(sample_median(5,P=[0.3,0.7]) print(sample_median(5,P=[0.3,0.7]) * Expected Output * 4.5 4.0 2.0 1.0
Computers and Technology
1 answer:
TiliK225 [7]2 years ago
7 0

Answer:

import numpy as np

def sample_median(n, P):  

   return np.median( np.random.choice ( np.arange (1, len(P) + 1 ), n, p = P ) )

print(sample_median(10,[0.1 0.2 0.1 0.3 0.1 0.2]))

print(sample_median(10,[0.1 0.2 0.1 0.3 0.1 0.2]))

print(sample_median(5, [0.3,0.7])

print(sample_median(5, [0.3,0.7])

Explanation:

  • Bring in the numpy library to use the median function provided by the numpy library.
  • Define the sample_median function that takes in 2 parameters and returns the median with the help of built-in random, choice and arrange functions.
  • Call the sample_median function by providing some values to test and then display the results.    

Output:

4.5

4.0

2.0

1.0

You might be interested in
You would like to help guide your company in choosing between valuing privacy and increasing the company's bottom line. What is
Ainat [17]

In the above case, the option that will help to guide your company in choosing between valuing privacy is a set of internal principles.

<h3>What are internal control principles?</h3>

The principles of internal control are known to be  needed in the management to set methods in place to make sure that company assets are kept.

Therefore, In the above case, the option that will help to guide your company in choosing between valuing privacy is a set of internal principles.

Learn more about internal principles from

brainly.com/question/27015769

#SPJ1

6 0
2 years ago
What can be designed to create annoying glitches or destroy data
Yanka [14]
Viruses can cause this.
3 0
3 years ago
Which automatic startup option should you choose when windows' startup fails immediately after installing a new driver but befor
Luda [366]

Answer:

last known good configuration

Explanation:

If you're having difficulties starting Windows, the Last Known Good Configuration, or LKGC for short, is a technique to get it started. It loads the drivers and registry data from the last time you began and shut down your computer successfully.

3 0
2 years ago
.Visual Studio .NET’s ___________ feature displays all the members in a class
Alex

Answer:d)Intellisense

Explanation: Visual Studio.NET is the tool for the development of the application .Intellisense is the type of code that is found in the Visual Studio.NET which is used for the intelligent completion of text or code. The factors present in the Visual studio NET has are tracking of the values, increasing the understanding of code,presenting the class member etc.

Other options are incorrect because real time error checking is for the checking of the error raising at the time of execution, Quick info is for gaining data rapidly and outlined code are for display of the hierarchical structure of codes.Thus, the correct option is option(d).

3 0
3 years ago
What is the legal right granted to all authors and artists that gives them sole ownership and use of their words, software, pict
ICE Princess25 [194]

Answer:

copyright

Explanation:

3 0
3 years ago
Other questions:
  • What was the purpose of the Declaration of Independence and what led to it​
    10·1 answer
  • How can investors receive compounding returns
    13·1 answer
  • Which of the following software programs provides for e-mail communication?. A. Access. B. Word Perfect. C. Outlook. D. Excel
    15·2 answers
  • Why is it important to minimize cable clutter in a rack?
    11·1 answer
  • True or False: <br> The object reference can be used to polymorphically store any class in Java.
    13·1 answer
  • If you do not specify any criteria in a delete query, Access will delete all the records in the table. Truth or False
    11·1 answer
  • Why might you receive a tax refund from the irs
    6·1 answer
  • I need help with writing the code in Python that draws an arrow pointing to the right.
    15·1 answer
  • JAVA NEED HELP ASAP
    7·1 answer
  • Question 8 A data analyst is working with a data frame named stores. It has separate columns for city (city) and state (state).
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!