Since numpy version 1.7 you can use numpy.random.choice()
:
elements = ['one', 'two', 'three']
weights = [0.2, 0.3, 0.5]
from numpy.random import choice
print(choice(elements, p=weights))
More Related Contents:
- Efficiently Using Multiple Numpy Slices for Random Image Cropping
- What is the difference between flatten and ravel functions in numpy?
- Computing the correlation coefficient between two multi-dimensional arrays
- How to return 0 with divide by zero
- How to get the index of a maximum element in a NumPy array along one axis
- Problems with pip install numpy – RuntimeError: Broken toolchain: cannot link a simple C program
- How do I fit a sine curve to my data with pylab and numpy?
- Most efficient way to find mode in numpy array
- numpy: formal definition of “array_like” objects?
- Most efficient way to forward-fill NaN values in numpy array
- Calculating the area under a curve given a set of coordinates, without knowing the function
- Why does numpy.zeros takes up little space
- Generalise slicing operation in a NumPy array
- how is axis indexed in numpy’s array?
- Efficiently Calculating a Euclidean Distance Matrix Using Numpy
- Convert RGB to black OR white
- Map each list value to its corresponding percentile
- List to array conversion to use ravel() function
- “Converting” Numpy arrays to Matlab and vice versa
- Most efficient way to calculate radial profile
- Adding a field to a structured numpy array
- How can I upgrade NumPy?
- Concatenate sparse matrices in Python using SciPy/Numpy
- How to install matplotlib with Python3.2
- Plotting implicit equations in 3d
- sampling random floats on a range in numpy
- How does the axis parameter from NumPy work?
- Fast interpolation of grid data
- numpy faster than numba and cython , how to improve numba code
- Interweaving two NumPy arrays efficiently