You can use np.random.choice
with replace=False
as follows:
np.random.choice(vec,size,replace=False, p=P)
where vec
is your population and P
is the weight vector.
For example:
import numpy as np
vec=[1,2,3]
P=[0.5,0.2,0.3]
np.random.choice(vec,size=2,replace=False, p=P)
More Related Contents:
- Consistently create same random numpy array
- How to specify upper and lower limits when using numpy.random.normal
- Binary random array with a specific proportion of ones?
- How to get a normal distribution within a range in numpy? [duplicate]
- Generate a random sample of points distributed on the surface of a unit sphere
- Difference between np.random.seed() and np.random.RandomState()
- Should I use `random.seed` or `numpy.random.seed` to control random number generation in `scikit-learn`?
- Creating same random number sequence in Python, NumPy and R
- Generating Discrete random variables with specified weights using SciPy or NumPy
- Better way to shuffle two numpy arrays in unison
- Shuffling NumPy array along a given axis
- How to generate a random normal distribution of integers
- Vectorizing `numpy.random.choice` for given 2D array of probabilities along an axis
- Working with floating point NumPy arrays for comparison and related operations
- Generate random locations within a triangular domain
- Generate random array of floats between a range
- Numpy where function multiple conditions
- python numpy ValueError: operands could not be broadcast together with shapes
- Dropping infinite values from dataframes in pandas?
- How can I add new dimensions to a Numpy array?
- How to generate random numbers that are different? [duplicate]
- Check if two 3D numpy arrays contain overlapping 2D arrays
- Is there anything faster than dict()?
- NaNs as key in dictionaries
- Why list comprehension is much faster than numpy for multiplying arrays?
- how to annotate heatmap with text in matplotlib
- How to hash a string into 8 digits?
- python dict to numpy structured array
- Python’s and Numpy’s nan and set
- Is there a MATLAB accumarray equivalent in numpy?