def __init__(self, arrays, lengths=None):
if lengths is None:
# Without provided lengths, `arrays` is interpreted as a list of arrays
# and self.lengths is set to the list of lengths for those arrays
self.arrays = arrays
self.stacked = np.concatenate(arrays, axis=0)
self.lengths = np.array([len(a) for a in arrays])
else:
# With provided lengths, `arrays` is interpreted as concatenated data
# and self.lengths is set to the provided lengths.
self.arrays = np.split(arrays, np.cumsum(lengths)[:-1])
self.stacked = arrays
self.lengths = np.asarray(lengths, dtype=int)
assert all(len(a) == l for a, l in util.safezip(self.arrays, self.lengths))
self.boundaries = np.concatenate([[0], np.cumsum(self.lengths)])
assert self.boundaries[-1] == len(self.stacked)
评论列表
文章目录