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
When you are almost done with your soup and want to get at the last little bit, how should you do this 2
pav-90 [236]

Answer:

<u>B. Tip the bowl slightly, then spoon up the last bit</u>

Explanation:

Generally speaking none of the other answers made much of sense.. "tip the bowl from side to side" doesn't help you at all, neither does "Keep spooning as much as you can, then stop eating". Neither of these will help you spoon up the last little bit, <u>the most logical answer is B. "Tip the bowl slightly, then spoon up the last bit"</u>. If this is not the correct answer then it'd be D, but I don't believe/feel that it's "poor etiquette" to "leave the last little bit".

7 0
2 years ago
What is the first step in finding a solution to a problem?
Law Incorporation [45]

Answer:

Can i have a points? Tysmm

5 0
3 years ago
Read 2 more answers
According to ________ law, in a sealed chamber, the pressure and temperature of a gas are directly related to each other.
Vaselesa [24]

Gay- Lussac's Law.  <span>A law stating that the volumes of gases undergoing a reaction at constant pressure and temperature are in a simple ratio to each other and to that of the product</span>

<span>.</span>


6 0
3 years ago
Write a little man program that accepts three values as input and produces the largest of the three as output.
ki77a [65]
Required: program to return the largest of three numbers.

pseudocode

input parameters, int A,B,C;
int T; // temporary storage
if (A>B) T=A;
else T=B;
if (T>C) print(T);
else print(C);


5 0
3 years ago
What is a killer app??
mars1129 [50]
Application of a new technology and is much superior to rival products
6 0
3 years ago
Other questions:
  • Can someone fix this so that it only says "its a payday" on 15 and 30 and on all other days "sorry, it's not payday"
    9·1 answer
  • How many rows and columns does ms-excel 2007 have???
    10·1 answer
  • A ____ is a program that lets computer users create and access a collection of organized data.
    14·1 answer
  • ____ allows you to control how objects enter, move on and exit slides
    13·2 answers
  • Create a query that shows columns employee last name, job title and hire date for those employees who joined the company on or a
    7·1 answer
  • Sustainable development is a goal towards which all human societies need to be moving. elaborate the statement in about 120 word
    9·1 answer
  • Which TWO of the following are input devices that are parts of a laptop computer?
    9·2 answers
  • What is Microsoft Excel?​
    13·1 answer
  • Please answer this question​
    6·1 answer
  • How can the two independent clauses below be combined to form a correct complete sentence? Check all that apply.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!