def binArray(x, binList, axis=0):
"""Binarize an array
x : array
Array to binarize
binList : list of tuple/list
This list contain the index to binarize the array x
axis : int, optional, [def: 0]
Binarize along the axis "axis"
-> Return the binarize x and the center of each window.
"""
nbin = len(binList)
x = np.swapaxes(x, 0, axis)
xBin = np.zeros((nbin,)+x.shape[1::])
for k, i in enumerate(binList):
if i[1] - i[0] == 1:
xBin[k, ...] = x[i[0], ...]
else:
xBin[k, ...] = np.mean(x[i[0]:i[1], ...], 0)
return np.swapaxes(xBin, 0, axis), [(k[0]+k[1])/2 for k in binList]
评论列表
文章目录