1

Weighted Random Choice

Unsolved
Prob. and Stats

Difficulty: 2 | Problem written by mesakarghm
Given a list we want to pick randomly some elements from it, but we need that the probabilities of picking a specific element to be defined using a weight.

Implement a function weighted_picks such that given a value n, it picks a set of random values such that the chance to pick the index i is given by the weights[i]. 

Inputs: weights (list of weights), N (number of random choices to generate)

Outputs: list of weighted random choice numbers

For reproducibility in the test cases, be sure to initialize the random seed with the following code: np.random.seed(0)

Sample Input:
<class 'list'>
weights: [0.1, 0.2, 0.3]
<class 'int'>
n_picks: 3

Expected Output:
<class 'numpy.ndarray'>
[3 1 2]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Ullam atque obcaecati quia possimus pariatur placeat, qui tempora excepturi aut aliquid corrupti a, asperiores autem explicabo eligendi cumque, voluptatibus autem minus necessitatibus. Culpa praesentium tempora quisquam itaque animi, eos voluptatibus expedita unde iure ut quaerat nemo cumque modi optio, voluptates natus ipsum aperiam omnis maiores dicta id facilis totam asperiores, neque temporibus magnam magni provident ipsum veniam cupiditate cum quasi deserunt.

Ex assumenda illo magni doloribus vel repudiandae aut error exercitationem amet, quam obcaecati dolore exercitationem omnis, perspiciatis esse totam ut libero maxime ipsa sint? Inventore eius delectus enim et debitis rem id quibusdam quis, ad mollitia autem beatae maiores veniam iusto quos velit repudiandae deserunt, aut tempora soluta molestiae voluptatem nostrum laudantium maxime.

Doloribus fuga commodi quibusdam, ipsam eaque repellat delectus voluptate blanditiis rem.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)