def _bin_results(self, length, results):
"""
Add hits to the bins corresponding to these results. length_hit_bins
is flattened, so we need to figure out the offset for this hit by
factoring the sizes of the other dimensions.
"""
hit_bin = np.zeros(results.shape[0], dtype='int64')
multi = 1
good = np.ones(results.shape[0], dtype='bool')
for dim in range(len(self.out_labels)):
for d1 in range(dim):
multi *= self.bin_edges[d1].size
if dim == 0 and len(self.out_labels)==1:
try:
digi = np.digitize(results, self.bin_edges[dim])
except ValueError:
# The user probably did something like
# return a * b rather than
# return a[0] * b[0], which will only happen
# for single field functions.
digi = np.digitize(results[0], self.bin_edges[dim])
else:
digi = np.digitize(results[:,dim], self.bin_edges[dim])
too_low = (digi == 0)
too_high = (digi == self.bin_edges[dim].size)
self.too_low[dim] += (too_low).sum()
self.too_high[dim] += (too_high).sum()
newgood = np.bitwise_and(np.invert(too_low), np.invert(too_high))
good = np.bitwise_and(good, newgood)
hit_bin += np.multiply((digi - 1), multi)
digi_bins = np.arange(self.length_bin_hits[length].size+1)
hist, digi_bins = np.histogram(hit_bin[good], digi_bins)
self.length_bin_hits[length] += hist
评论列表
文章目录