random.randint to get random integers


We get random integers or array of random integers based on the supplied parameters ( below ).
lowInt, Lowest integer ( inclusive ) returned
highInt,Optional, Highest value ( exclusive ) returned
sizeInt,Optional, int or tupple of ints of returned
dtypeDtype,Optional, Data Type of returned
Output is integer or array of integers based on the input parameters.

Example with low

import numpy as np
my_data=np.random.randint(4)
print(my_data) #3

Example with low and high value

my_data=np.random.randint(4,10) # 8

With low, high and size

my_data=np.random.randint(4,10,size=5)
print(my_data)
Output
[6 4 4 4 5]
We will use one tuple as size parameter
my_data=np.random.randint(4,high=10,size=(3,2)) 
print(my_data)
Output
[[5 8]
 [8 7]
 [5 6]]

Using dtype

import numpy as np
my_data=np.random.randint(4,high=7,size=(3,3),dtype='int16') 
print(my_data)
Output
[[6 4 5]
 [5 6 6]
 [4 6 5]]
Numpy rand()

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer