Yet another approach, using np.random.choice
:
>>> np.random.choice([0, 1], size=(10,), p=[1./3, 2./3])
array([0, 1, 1, 1, 1, 0, 0, 0, 0, 0])
More Related Contents:
- Creating same random number sequence in Python, NumPy and R
- Working with floating point NumPy arrays for comparison and related operations
- Generate random array of floats between a range
- Using numpy to build an array of all combinations of two arrays
- Find the row indexes of several values in a numpy array
- What are the differences between numpy arrays and matrices? Which one should I use?
- Working with big data in python and numpy, not enough ram, how to save partial results on disc?
- How to apply a disc shaped mask to a NumPy array?
- How to remove specific elements in a numpy array
- Shuffle an array with python, randomize array item order with python
- Find nearest indices for one array against all values in another array – Python / NumPy
- Get the position of the largest value in a multi-dimensional NumPy array
- Convert a 1D array to a 2D array in numpy
- Using Numpy Vectorize on Functions that Return Vectors
- How to extend an array in-place in Numpy?
- “In” operator for numpy arrays?
- Numpy: efficient way to generate combinations from given ranges
- Python: slicing a multi-dimensional array
- NumPy chained comparison with two predicates
- How to count values in a certain range in a Numpy array?
- Numpy array dimensions
- How to access a column in a list of lists in python
- Techniques for working with large Numpy arrays? [duplicate]
- Numpy select rows based on condition
- Sorting a python array/recarray by column
- Numpy Array Get row index searching by a row
- Resample a numpy array
- Creating a numpy array of 3D coordinates from three 1D arrays
- How to use Python multiprocessing Pool.map to fill numpy array in a for loop
- Is this the best way to add an extra dimension to a numpy array in one line of code?