def flat2triu(a, dim):
    """ Produces an upper triangular matrix of dimension dim from the elements of the given vector. """
    res = zeros((dim, dim))
    index = 0
    for row in range(dim):
        res[row, row:] = a[index:index + dim - row]
        index += dim - row
    return res
dataset/ETHPy150Open pybrain/pybrain/pybrain/utilities.py/flat2triu/original