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]
3 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]3 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
Mrs. Schlair has an annual salary of $96,402.<br> a. What would her semimonthly salary be?
amid [387]

Answer:$4016.75

Explanation:64333/24

3 0
3 years ago
Give me 4 examples of things to consider as a sound designer?<br> HURYYYYY IM TIMED
alisha [4.7K]

Answer:

Sound design components include sound effects or SFX sound design, mixing, Foley sound design, dialogue, and music.

Explanation:

3 0
3 years ago
How to transfer bookmarks to new computer
Romashka-Z-Leto [24]

Explanation:

On your computer, open Chrome

.At the top right, click More

.Select Bookmarks Import Bookmarks and Settings

.Select the program that contains the bookmarks you'd like to import.Click Import.

Click Done

3 0
3 years ago
Suppose x and y are int variables and ch is a char variable. Consider the following input: 5 28 36 What value (if any) is assign
eimsori [14]

Answer:

x is assigned "5", y is assigned "28", and ch is assigned "$"

Explanation:

#include <stdio.h>

#include <iostream>

using namespace std;

int main()

{

   int x,y;

   char ch;

   x = 5;

   y = 28;

   ch = 36;

   cout<<x<<endl<<y<<endl;

   cout<<ch;

   return 0;

}

4 0
3 years ago
What is a constructor? Why would you include a constructor in a class?
QveST [7]

Answer:

Constructor in the class is the member function that gets into action when any new object gets created in the class ,it gets invoked. It does not have any return type and no void return.

The constructor is used in the class because there is the requirement for the initializing of the new object and then only object can do the functioning in the program.

4 0
3 years ago
Other questions:
  • What item on a business card is generally the most prominent?
    13·2 answers
  • It is important that researchers design rigorous study methods to eliminate: a. inferences. b. the need for a CONSORT flow chart
    10·1 answer
  • Question: A famous Disney Movie partially takes place in this city.
    15·2 answers
  • Design a new Triangle class that extends the abstract
    13·1 answer
  • Which of the following is a malicious program that can replicate and spread from computer to computer?
    8·2 answers
  • Please help. 15 points!!!!
    8·2 answers
  • True or False <br><br> Rootkits are only made by black-hat hackers.
    8·1 answer
  • What is the d/c b/n information rich and information poor society​
    13·1 answer
  • PLEASE I NEED HELP FAST
    8·1 answer
  • . Which responsibility belongs to the marketing function?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!