numpy.random.random_integers() is one of the function for doing random sampling in numpy. It returns an array of specified shape and fills it with random integers from low (inclusive) to high (exclusive), i.e. in the interval
Syntax : numpy.random.random_integers(low, high=None, size=None)
low : [int] Lowest (signed) integer to be drawn from the distribution.But, it works as a highest integer in the sample if high=None.
high : [int, optional] Largest (signed) integer to be drawn from the distribution.
size : [int or tuple of ints, optional] Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
Return : Array of random integers in the interval
[low, high)or a single such random int if size not provided.
Code #1 :
Output 1D Array filled with random integers : [1 1 4 1]
Code #2 :
Output 2D Array filled with random integers : [[2 3 1] [2 2 3] [3 3 3]]
Code #3 :
Output 3D Array filled with random integers : [[[4 8 5 7] Output 3D Array filled with random integers : [[[5 1 5] [5 4 1]] [[3 6 4] [4 5 3]]]
- Random sampling in numpy | random() function
- Random sampling in numpy | randint() function
- Random sampling in numpy | sample() function
- Random sampling in numpy | random_sample() function
- Random sampling in numpy | ranf() function
- numpy.random.randn() in Python
- numpy.random.rand() in Python
- rand vs normal in Numpy.random in Python
- Create a Numpy array with random values | Python
- Python | random.sample() function
- Numpy Meshgrid function
- Python | numpy.cov() function
- Numpy MaskedArray.any() function | Python
- Numpy MaskedArray.std() function | Python
- Numpy MaskedArray.var() function | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.