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
Read the scenarios below, then use the drop-down menus to decide if you should use a database.
Romashka [77]

Answer:

A. The parent-teacher orginization keeps a log of cookies sales to raise money for the elementary school.

Explanation:

5 0
3 years ago
How can the Internet help our country to be a leader in technology?
BigorU [14]

Answer:

it can help in the aspect of making technologies to be fastly operated with fast internet connection there by it top among all other countries

4 0
2 years ago
The Mohs scale is used to express which mineral property?
olchik [2.2K]
Its answer is c. hardness

5 0
2 years ago
A communication between two devices is over the maximum limit of an ethernet frame size. The Transmission Control Protocol (TCP)
umka2103 [35]

Answer:

D. Sequence number

Explanation:

The sequence number facilitates the keeping track of many segments. This enables it to determine which segments out of many in which it should be in. The sequence number field is usually 32 bits.

Sequence numbers are used in transmitting data because of their importance. Since data is transmitted in packets, they can be lost and as such the receiver uses the sequence numbers to reorder them.

6 0
3 years ago
How does the CSMA/CD protocol resolve when two network adapters on the same network transmit at the same time?
KengaRu [80]

Answer:

If two network adapters on the same network transmit at the same time, one of the adapters would stop transmitting until the second adapter has finished transmitting before retransmission

Explanation:

Carrier Sense Multiple Access with Collision Detection (CSMA/CD) is a network protocol used to prevent data collision. CSMA/CD detects collisions by sensing transmissions from other nodes. If a collision is detected, the node stops transmitting, sends a jam signal, and then waits for some time until the channel is idle before retransmission.

If two nodes on the network start transmitting at the same time, the nodes will detect the collision and take the appropriate action.

If two network adapters on the same network transmit at the same time, one of the adapters would stop transmitting until the second adapter has finished transmitting before retransmission

4 0
2 years ago
Other questions:
  • A survey of results on mobile phone datasets analysis
    5·1 answer
  • There are 12 inches in a foot and 3 feet in a yard. Create a class named InchConversion. Its main() method accepts a value in in
    10·1 answer
  • Which of the following are not parts of a message? Select all that apply.
    12·1 answer
  • A lookup field allows the user to select from a list of values when updating the contents of a field. true or false.
    11·1 answer
  • Create a program in c/c++ which accepts user input of a decimal number in the range of 1 -100. Each binary bit of this number wi
    9·1 answer
  • 1. Write a generic method that compares its 2 arguments using the equals method and returns true if they are equal and false oth
    8·1 answer
  • Histogram 9AMAA 12/01/2021.
    9·1 answer
  • We want to implement a data link control protocol on a channel that has limited bandwidth and high error rate. On the other hand
    13·1 answer
  • Sebutkan contoh komputer analog, komputer digital, dan komputer hybrid
    9·1 answer
  • The data _____ component of a database management system (DBMS) is used to create and maintain the data dictionary.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!