I have a task to randomly chose 100 element from a population of alpha list [a,b,c,d] with corresponding frequency (probability) [0.1, 0.3, 0.2, 0.4]. There are many different ways to do it. But here I want what returned after this function call (suppose there is one) is a list of the number of elements chosen. Say, it returns (20,20,30,30), then it means 20 of elements a are chosen, 20 of elements c are chosen, etc. I figured that np.random.multinomial is the way to go. Following the above example, I will need to call the function np.random.multinomial(100, [0.1,0.3,0.2,0.4],1 ). Is this right ? Thanks.
Related: fast way to uniformly remove 10% of all the elements in a given list of python
Related Posts:
- What does random.sample() method in python do?
- Random string generation with upper case letters and digits
- How can I randomly select an item from a list?
- How to get a random number between a float range?
- Python: Array v. List
- Generate random sentences in python
- Shuffle an array with python, randomize array item order with python
- Generate random colors (RGB)
- Get a random sample with replacement
- How to randomly get 0 or 1 every time?
- Simple way to create matrix of random numbers
- Generate a random letter in Python
- Random word generator- Python
- Shuffle an array with python, randomize array item order with python
- How can I reverse a list in Python?
- Python Progress Bar
- Most efficient way to find mode in numpy array
- Python error “ImportError: No module named”
- How to groupby based on two columns in pandas?
- How do I append one string to another in Python?
- Python Progress Bar
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Python: list of lists
- How can I split and parse a string in Python?
- numpy matrix vector multiplication
- whitespace in regular expression
- How do I read CSV data into a record array in NumPy?
- Basic explanation of python functions
- TypeError: ‘Series’ objects are mutable, thus they cannot be hashed problemwith column
- How to rename a file using Python
- Cosine Similarity between 2 Number Lists
- How to install python3 version of package via pip on Ubuntu?
- django: TypeError: ‘tuple’ object is not callable
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ImportError: No module named PIL
- Maximum and Minimum values for ints
- How do I list all files of a directory?
- How to check whether a str(variable) is empty or not?
- Clear variable in python
- Python 3.6.0 syntax error “Missing parentheses in call to ‘print’ [duplicate]
- How to get coverage reporting when testing a pytest plugin?
- TypeError: method() takes 1 positional argument but 2 were given
- How to add title to subplots in Matplotlib
- ‘pip3’ is not recognized as an internal or external command, operable program or batch file
- Apply function to each element of a list
- How to display text in pygame?
- Python Nested Loops To Print Rectangle With Asterisks
- How to fix this strange error: “RuntimeError: CUDA error: out of memory”
- Combine two columns of text in pandas dataframe
- How can I rename a conda environment?
- django import error – No module named core.management
- How to change a ‘LinearSegmentedColormap’ to a different distribution of color?
- Using python’s eval() vs. ast.literal_eval()
- How can I stop a While loop?
- Python: can’t assign to literal
- “Initializing” variables in python?
- Difference between except: and except Exception as e:
- Flask raises TemplateNotFound error even though template file exists
- Python: Declare as integer and character
- How to install pytorch in windows?
- Python TypeError must be str not int
- “Unicode Error “unicodeescape” codec can’t decode bytes… Cannot open text files in Python 3
- Pandas join issue: columns overlap but no suffix specified
- How to downgrade python from 3.7 to 3.6
- How to turn on line numbers in IDLE?
- Python socket.error: [Errno 111] Connection refused
- Windows- Pyinstaller Error “failed to execute script ” When App Clicked
- Python: What is the correct MIME type for attaching html file to email
- Linear regression with matplotlib / numpy
- Solving “500: Internal Server Error, nbconvert failed: xelatex not found in PATH”
- Using Look Up Tables in Python
- Parallel Python: What is a callback?
- ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- how to exit a python script in an if statement
- How to add column to numpy array
- OpenCV NoneType object has no attribute shape
- AttributeError: ‘str’ object has no attribute ‘items’
- ImportError: No module named Crypto.Cipher
- Not able to pip install pickle in python 3.6
- How to print Unicode character in Python?
- Coalesce values from 2 columns into a single column in a pandas dataframe
- Unknown format code ‘f’ for object of type ‘str’- Folium
- Pyinstaller setting icons don’t change
- Can not click on a Element: ElementClickInterceptedException in Splinter / Selenium
- How to split elements of a list?
- How can I find script’s directory?
- Porting Perl to Python
- Find object in list that has attribute equal to some value (that meets any condition)
- What is the purpose of the single underscore “_” variable in Python?
- Must have equal len keys and value when setting with an iterable
- print(__doc__) in Python 3 script
- Python IOError: File not open for reading
- Strange Exception in Tkinter callback
- How to resolve “ImportError: DLL load failed:” on Python?
- ‘module’ has no attribute ‘urlencode’
- Cannot concatenate ‘str’ and ‘float’ objects?
- Python Text Menu Infinite Loop
- Install pip for python 3.5
- How do I represent and work with n-bit vectors in Python?
- How to repeat individual characters in strings in Python