xxxxxxxxxx
>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
xxxxxxxxxx
import numpy as np
# if the shape is not mentioned the output will just be a random integer in the given range
rand_int = np.random.randint(5,10)
print("First array", rand_int)
rand_int2 = np.random.randint(10,90,(4,5)) # random numpy array of shape (4,5)
print("Second array", rand_int2)
rand_int3 = np.random.randint(50,75,(2,2), dtype='int64')
print("Third array", rand_int3)
print(rand_int3.dtype)
# First array 7
# Second array [[86 10 37 84 40]
# [66 49 29 73 37]
# [39 87 36 20 87]
# [76 86 89 69 50]]
# Third array [[74 73]
# [71 50]]
# int64
xxxxxxxxxx
import numpy as np
# Generate a single random integer between 0 and 9
rand_int = np.random.randint(10)
print(rand_int)
# Generate a random integer array of size 5x5 between 0 and 99
rand_int_array = np.random.randint(100, size=(5, 5))
print(rand_int_array)
xxxxxxxxxx
# random.randint(low, high=None, size=None, dtype=int)
# [low,high) if high is given, else [0, low)