Skip to content

Commit

Permalink
Merge pull request #11 from guiweber/master
Browse files Browse the repository at this point in the history
Prevent invalid operations in xlogx
  • Loading branch information
raphaelvallat authored Sep 21, 2021
2 parents 96c28d2 + a28e37d commit 275216a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion antropy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ def _xlogx(x, base=2):
otherwise. This handles the case when the power spectrum density
takes any zero value.
"""
return np.where(x == 0, 0, x * np.log(x) / np.log(base))
x = np.asarray(x)
xlogx = np.zeros(x.shape)
xlogx[x < 0] = np.nan
valid = x > 0
xlogx[valid] = x[valid] * np.log(x[valid]) / np.log(base)
return xlogx

0 comments on commit 275216a

Please sign in to comment.