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
Select the correct answer.
Umnica [9.8K]

Answer:

OB. by zooming in on them

hope it helps

7 0
3 years ago
2(x-5)-3(3-x)=1/2(x-2)
lana [24]

you distribute and then combine like terms. x=4 :))

4 0
3 years ago
When a machine on the public network wants to reach the server at 172.30.0.10, which ip will it use?
Anton [14]
The IP address that it will use is 192.168.16.100
3 0
4 years ago
Read 2 more answers
Evaluating how current, credible, and unbiased a source is ensures:
Tanya [424]

The answer is

A. your information is more accurate and useful

I hope it helps you. Please mark me brainliest answer.

6 0
3 years ago
How to delay sending an email in office 365
expeople1 [14]
You can’t it’s impossible unless your a hackers
3 0
3 years ago
Other questions:
  • The _______ displays the name of the open file and the program.
    13·1 answer
  • In setting up a small office network, the network administrator decides to assign private IP addresses dynamically to workstatio
    12·1 answer
  • A(n)___ is divided into rows and columns.<br> What goes in the blank?
    7·1 answer
  • From the ages of 18 to 24, individuals born from 1980 to 1984 held an average of 6.2 jobs—which is slightly higher than the numb
    10·1 answer
  • Write a complete program whose class name is hello and that displays hello, world on the screen.
    13·2 answers
  • From the standpoint of the governing bodies of .com, why is it important that owners of individual domains maintain authoritativ
    5·1 answer
  • Assume that you have an array of integers named arr. Which of these code segments print the same results?
    15·1 answer
  • All of the following municipal securities are quoted on a yield basis EXCEPT: A) term bonds. B) secured bonds. C) tax-anticipati
    10·1 answer
  • Consider a two-link network where Host A is connected to the router by a 1 Mbps link with 10 ms propagation delay and the router
    6·1 answer
  • Trish has bought a new computer that she plans to start on after a week
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!