import numpy as np
x = np.zeros(10)
positions = np.random.choice(np.arange(10), 3, replace=False)
x[positions] = np.random.normal(0, 1, 3)
x
Python: How to generate a vector with nonzero entries at random positions?