How can we create a random array using numpy?
To create a random array, you can utilize the random module in the NumPy library. Here are several common methods:
- Generate random numbers using NumPy.
- Generate a random array with shape (3, 2) using NumPy.
import numpy as np
arr = np.random.rand(3, 2)
print(arr)
- generate random numbers from a standard normal distribution using numpy.
import numpy as np
arr = np.random.randn(3, 2)
print(arr)
- Generate a random integer using NumPy.
import numpy as np
arr = np.random.randint(1, 10, size=(3, 2))
print(arr)
These are just some common methods for creating random arrays, but NumPy also offers more random functions and parameter options for you to choose from based on your needs.