python - Numpy Uniform Distribution With Decay -


i'm trying construct matrix of uniform distributions decaying 0 @ same rate in each row. distributions should between -1 , 1. i'm looking @ construct resembles:

[[0.454/exp(0) -0.032/exp(1) 0.641/exp(2)...]  [-0.234/exp(0) 0.921/exp(1) 0.049/exp(2)...]  ...  [0.910/exp(0) 0.003/exp(1) -0.908/exp(2)...]] 

i can build matrix of uniform distributions using:

w = np.array([np.random.uniform(-1, 1, 10) in range(10)]) 

and can achieve desired result using for loop with:

for k in range(len(w)):     l in range(len(w[0])):         w[k][l] = w[k][l]/np.exp(l) 

but wanted know if there better way of accomplishing this.

you can use numpy's broadcasting feature this:

w = np.random.uniform(-1, 1, size=(10, 10)) weights = np.exp(np.arange(10)) w /= weights 

Comments