Using np.random.randint

Question Q6.7.1

Explain the difference between

In [x]: a = np.array([6,6,6,7,7,7,7,7,7])
In [x]: a[np.random.randint(len(a), size=5)]
array([7, 7, 7, 6, 7])      # (for example)

and

In [x]: np.random.randint(6, 8, 5)
array([6, 6, 7, 7, 7])      # (for example)

Solution

To access solutions, please obtain an access code from Cambridge University Press at the Lecturer Resources page for my book (registration required) and then sign up to scipython.com providing this code.