rate==0.0 fix

Original issue:
https://github.com/numpy/numpy/issues/5046
This bug is caused by using numpy.where.
This command will evaluate both expression first and then return based on condition. However, if rate==0.0, the expression will cause an error anyway. We replace the same process with a if condition and the fix is successful.