def convertSequenceToTimeWindows(DSseq, NewClass, winsize):
    """ Converts a sequential classification dataset into time windows of fixed length.
    Assumes the correct class is given at the last timestep of each sequence. Incomplete windows at the
    sequence end are pruned. No overlap between windows.

    :arg DSseq: the sequential data set to cut up
    :arg winsize: size of the data window
    :arg NewClass: class of the windowed data set to be returned (gets initialised with indim*winsize, outdim)"""
    assert isinstance(DSseq, SequentialDataSet)
    #assert isinstance(DSwin, SupervisedDataSet)

    DSwin = NewClass(DSseq.indim * winsize, DSseq.outdim)
    nsamples = 0
    nseqs = 0
    si = r_[DSseq['sequence_index'].flatten(), DSseq.endmarker['sequence_index']]
    for i in range(DSseq.getNumSequences()):
        # get one sequence as arrays
        input = DSseq['input'][si[i]:si[i + 1], :]
        target = DSseq['target'][si[i]:si[i + 1], :]
        nseqs += 1
        # cut this sequence into windows, assuming class is given at the last step of each sequence
        for k in range(winsize, input.shape[0], winsize):
            inp_win = input[k - winsize:k, :]
            tar_win = target[k - 1, :]
            DSwin.addSample(inp_win.flatten(), tar_win.flatten())
            nsamples += 1
            ##print("added sample %d from sequence %d: %d - %d" %( nsamples, nseqs, k-winsize, k-1))
    print(("samples in original dataset: ", len(DSseq)))
    print(("window size * nsamples = ", winsize * nsamples))
    print(("total data points in original data: ", len(DSseq) * DSseq.indim))
    print(("total data points in windowed dataset: ", len(DSwin) * DSwin.indim))
    return DSwin
dataset/ETHPy150Open pybrain/pybrain/pybrain/tools/datasettools.py/convertSequenceToTimeWindows/original