Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Random numbers in NumPy are easy! ๐ŸŽฒ

14.9K views on YouTube

#coding #python #numpy

Random numbers in NumPy are useful for simulations,
modeling, applying random transformations, and testing purposes.

rng = np.random.default_rng()
print(rng.integers(low=1, high=7, size=(3, 4))) # 3×4 array of Ints

np.random.seed()
print(np.random.uniform(low=-1, high=1, size=(3, 2))) # floats between 2 values

# Shuffle
array = np.array([1, 2, 3, 4, 5])
rng.shuffle(array)
print(array)

# Random Choice
fruits = np.array([“๐ŸŽ”, “๐ŸŠ”, “๐ŸŒ”, “๐Ÿฅฅ”, “๐Ÿ”])
print(rng.choice(fruits, size=(3, 3)))