dimanche 27 octobre 2019

numpy.random.uniform applied to index of array produces integers

I want to populate an array with uniformly chosen floats, but when I try to do that I get integers instead:

#Initial parameters
P = np.full(1, 0)
lower_bounds = np.full(1, 0)
upper_bounds = np.full(1, np.pi)

def candidate(P):
    for k in range(len(P)):
        P[k] = np.random.uniform(lower_bounds[k],upper_bounds[k])
    return P

print(candidate(P))

This prints [0], [1], [2], or [3], whereas

print(np.random.uniform(lower_bounds[0],upper_bounds[0]))

prints a float, as desired. I'm not sure why this happens.




Aucun commentaire:

Enregistrer un commentaire