python random array code example
Example 1: how to get a random element from an array in python
import random
names=['Mark', 'Sam', 'Henry']
random_array_item=random.choice(names)
print(random_array_item)
for j in range(names):
print(random.choice(names))
Example 2: random array numpy
>>> np.random.rand(3,2)
array([[ 0.14022471, 0.96360618],
[ 0.37601032, 0.25528411],
[ 0.49313049, 0.94909878]])
>>> np.random.random_integers(low=0, high=9, size=(3,2))
array([[2, 3],
[2, 3],
[6, 3]])
Example 3: random matrix python
np.random.rand(3,2)
Example 4: numpy randn with a shape of another array
a = np.zeros([2, 3])
print(a.shape)
b = np.random.randn(*a.shape)
print(b.shape)