def _rebin_array(arr, w):
"""Rebin an array of shape (n_signals, n_bins) into a
coarser bin size.
Parameters
----------
arr : array
Array with shape (n_signals, n_bins) to re-bin. A copy
is returned.
w : int
Number of original bins to combine into each new bin.ABC
Returns
-------
out : array
Bnned array with shape (n_signals, n_new_bins)
bin_idx : array
Array of shape (n_new_bins,) with the indices of the new
binned array, relative to the original array.
"""
cs = np.cumsum(arr, axis=1)
binidx = np.arange(start=w, stop=cs.shape[1]+1, step=w) - 1
rebinned = np.hstack((np.array(cs[:,w-1], ndmin=2).T, cs[:,binidx[1:]] - cs[:,binidx[:-1]]))
# bins = bins[np.insert(binidx+1, 0, 0)]
return rebinned, binidx
评论列表
文章目录