How to pick a random element in an np array only if it isn't a certain value
If you're willing to accept probabilistic times and you have fewer than 50% ignored values, you can just retry until you have an acceptable value.
If you can't, you're going to have to go over the entire array at least once to know which values to ignore, but that takes n memory.
I'm using python.
I have what might be an easy question, though I can't see it.
If I have an array x = array([1.0,0.0,1.5,0.0,6.0]) and y = array([1,2,3,4,5])
I'm looking for an efficient way to pick randomly between 1.0,1.5,6.0 ignoring all zeros while retaining the index for comparison with another array such as y. So if I was to randomly pick 6.0 I could still relate it to y[4].
The reason for the efficient bit is that eventually I want to pick between possibly 10 values from an array of 1000+ with the rest zero. Depending on how intensive the other calculations become depends on the size of the array though it could easily become much larger than 1000.
Thanks