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
Top 5 best comedy or action movies.
Cloud [144]
Comedy movies you should watch is
grown ups
spider man into the spider verse
action movies you can do
like a fast and furious movie ?
some cool scary movies are
the strangers
insidious
and the serbian film :)
7 0
2 years ago
Read 2 more answers
________ is a process where authentication and permission will be passed on from one system to another, usually across multiple
hoa [83]

Answer: Federation

Explanation:

In multiple enterprises there are number of authentication processes to access resources and information so in order to avoid a large number of authentications we have a process called federation whereby all the authentication and authorization processes are passes from one system to the other within the enterprise.

3 0
2 years ago
Type size in a textbook may be used to indicate the relative importance of ideas.
Alborosie
Yes true 

hey is this one of your questions on a science packet if so it is called explore ring Earth's surface because I have the same packet with the same question on it
3 0
2 years ago
Read 2 more answers
What type of object can offer the most effective way to display data and calculations in a presentation?
poizon [28]

This is definitely an opinion, but an excel you can do A and D and just about the same as B also

<u>So i'd say C </u>

8 0
2 years ago
what is the best paper choice for printing a book with 1000 pages A. Cover B. Text C. Index D. Newsprint​
Eva8 [605]

Answer:

B

Explanation:

Text is the best paper choice.

Have a great day

3 0
2 years ago
Other questions:
  • The highly advanced decision support feature integrated within an electronic information system would support which activity?
    9·1 answer
  • Which of the following is NOT a web browser?<br> Safari<br> Chrome<br> Bing<br> Firefox
    8·2 answers
  • What can you do to manually exclude an individual from a recipient list?
    6·1 answer
  • 2 (01.01 LC)
    5·1 answer
  • 3.2 lesson practice edhesive ​
    6·1 answer
  • Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values
    13·1 answer
  • Write a program which populates an array with integer values read from a file. We do not know how many integers are in the file,
    8·1 answer
  • Help me asap please
    15·1 answer
  • If there are 18 people in your class and you want to divide the class into programming teams of 3
    7·1 answer
  • My friend has 200 subs and i have only 36 can you help me its ACYT ZR
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!