def add(self, arr):
if not isinstance(arr, np.ndarray):
arr = np.array(arr)
arr = arr.flatten()
self.min = min(self.min, arr.min())
self.max = max(self.max, arr.max())
self.sum += arr.sum()
self.num += len(arr)
self.sum_squares += (arr ** 2).sum()
indices = np.searchsorted(self.bucket_limits, arr, side='right')
new_counts = np.bincount(indices, minlength=self.buckets.shape[0])
if new_counts.shape[0] > self.buckets.shape[0]:
# This should only happen with nans and extremely large values
assert new_counts.shape[0] == self.buckets.shape[0] + 1, new_counts.shape
new_counts = new_counts[:self.buckets.shape[0]]
self.buckets += new_counts
评论列表
文章目录