Jan-Philip Gehrcke
unread,Feb 19, 2014, 9:29:02 AM2/19/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to bottl...@googlegroups.com
Hello,
I have another question for today. I see that bottleneck's nansum
returns inf or -inf if such values are within the set of numbers to be
summed:
>>> bn.nansum([1, np.nan, np.inf])
inf
>>> bn.nansum([1, np.nan, np.NINF])
-inf
This makes sense. In certain cases, however, people might want to ignore
(-)infs while summing up.
After taking the reciprocal of a large set of finite numbers X_i, the
result may contain inf in all places where X was zero. Summing up while
ignoring infs then requires something like this:
np.sum(x[np.isfinite(x)])
his involves creation of a boolean array which is then used for
indexing, so that only a subset of the reciprocal set of numbers is summed.
bottleneck seems to do a great job summing over arrays containing NaNs
while *ignoring* NaNs. Can't it just -- in a different function than
`nansum` also ignore (-)inf values? I guess that would be significantly
faster than doing np.sum(x[np.isfinite(x)]).
Thanks for insights,
Jan-Philip