I have a list which contains non-integers (three in this case) each of which I need to replace with a different Random Variate.
{27, 43.91405202, 56, 37, 31, 40, 50, 40.56562816, 39, 36, 27, 32, 40, 31, 18, 23, 26, 54.59260675, 21, 51}
Before I use ReplacePart I need the position of the offending elements. This line
Position[data, _?(! IntegerQ[#] &)]
produces this result of five elements, the middle three of which is my answer {{0}, {2}, {8}, {18}, {}}
I can work around that result with this
Drop[Position[data, _?(! IntegerQ[#] &), Heads -> False], -1]
My guess is that if I knew why the superfluous first and last elements were being generated I would be able to streamline my code.
Further discovery: I actually have a matrix. So my work around does not solve the problem for a list of lists
Position[data, Except[_Integer, _Real]]
orPosition[data, _Real]
? If this doesn't work for your matrix data, please update the question further $\endgroup$list /. x_Real :> RandomVariate[dist]
$\endgroup$