Relative Content

Tag Archive for pythonnumpyrandom

Efficient implementation for random sampling

If you have 4 lists A, B, C, and D that contain objects of particular length, like list A has n_a elements and all the elements are of width 1, list B has n_b elements and all the elements are of width 2, list C has n_c elements and all the elements are of width 3, and list D has n_d elements and all the elements are of width 4. The first goal is to create an array whose elements are randomly sampled from A, B, C and D according to a user defined probability distribution like {1: 0.25, 2: 0.25, 3: 0.5, 4: 0.0}. For instance, with distribution={1: 0.5, 2:0.5} the output grid should yield random elements with roughly 25% 1-width elements from list A, 25% 2-width elements from list B and 50% 3-width elements from list C, while disallowing 4-width elements.

sample using negated normal via numpy

I have a sorted list that I need to sample from. I want to favor the items towards each end of the list. In other words, I want to sample from the list using a negated normal function such that the first and last entries of the list are chosen more frequently than items in the middle of the list. I tried this: