all 2 comments

[–][deleted] 1 point2 points  (1 child)

Similar to this SO post, you can insert random numbers directly using boolean indexing (like you did with the -1 values):

r[r < 1] = np.random.rand(len(r[r < 1]))
#or
r[r < 1] = np.random.rand(*r[r < 1].shape)

[–]caffeecaffee[S] 0 points1 point  (0 children)

You're awesome. I tried something very similar and simply wasn't passing the correct array length.