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 all the mistakes in the following: There may be more than one.
sdas [7]

The if statement should have two equal signs, the elseif should be elif, and the else statement should have a colon at the end of it.  There might be more errors in the indentation but I cant know unless I see a picture of the problem. The print statement should be indented into the if, elif, and else statements.

4 0
3 years ago
Como se diz saia em inglês​
Montano1993 [528]

Answer:

I believe the translation would be "get out", but I'm not sure.

Explanation:

4 0
3 years ago
Read 2 more answers
Which tab will you use to format data in cells?
melamori03 [73]

Answer:

Right Click and select Format Cells (CTRL + 1)

Explanation:

To format cells in Excel, you select the cell(s) you want to format, right click, and in the dialogue box that appears select 'Format Cells'.

6 0
3 years ago
True or False: You should only use your mirrors to see behind you when parallel parking.
mafiozo [28]
False. You should always look /check ou tall mirrors periodicly
8 0
3 years ago
Read 2 more answers
The lower the weight of your water rocket the better it will fly. Why?
Gwar [14]

Yo, Big Shaq, the one and only

Man's not hot, never hot

Skrrat, skidi-kat-kat

Boom

Two plus two is four, minus one that's three, quick maths

Everyday man's on the block, smoke trees

See your girl in the park, that girl is a uckers

When the ting went quack-quack-quack, you man were ducking (you man ducked)

Hold tight, Asnee (my brotha), he's got the pumpy (big ting)

Hold tight, my man (my guy), he's got the frisbee

I trap, trap, trap on the phone, movin' that cornflakes

Rice Krispies, hold tight my girl, Whitney (my G)

On the road doin' ten toes, like my toes (like my toes)

You man thought I froze, I see a peng girl, then I pose (chilin')

If she ain't on it, I ghost, hah, look at your nose

6 0
3 years ago
Other questions:
  • Where is the bubble level on a tripod?
    6·2 answers
  • Audacity is _________ program that is free to download and is used by tens of millions of people worldwide.
    9·2 answers
  • What does the metric column in a routing table do?
    8·1 answer
  • Which type of exception would be detected if you used the conversion command Convert.ToDecimal to try to convert an ampersand?
    14·1 answer
  • It is possible to force the Hardware Simulator to load a built-in version of chip Xxx. This can be done by: Select one: a. makin
    10·2 answers
  • Which element of the Word program window displays information about the current document, such as number of pages, and also incl
    14·1 answer
  • Assignment 1: silly sentences edhesive
    7·1 answer
  • Which of these is not a valid form<br>layout in Microsoft Access?​
    11·1 answer
  • What can be viewed in the Tasks folder? Check all that apply
    14·1 answer
  • When you _______ the top row or the left column, you can keep column headings and row labels visible as you scroll through your
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!