def attribute_by_kper(self, attr, function=np.mean, idx_val=None):
    assert (attr in self.dtype.names)
    if (idx_val is not None):
        assert (idx_val[0] in self.dtype.names)
    kpers = list(self.data.keys())
    kpers.sort()
    values = []
    for kper in range(0, max(self._model.nper, max(kpers))):
        if (kper < min(kpers)):
            values.append(0)
        elif ((kper > max(kpers)) or (kper not in kpers)):
            values.append(values[(- 1)])
        else:
            kper_data = self.__data[kper]
            if (idx_val is not None):
                kper_data = kper_data[np.where((kper_data[idx_val[0]] == idx_val[1]))]
            v = function(kper_data[attr])
            values.append(v)
    return values
def attribute_by_kper(self, attr, function=np.mean, idx_val=None):
    assert (attr in self.dtype.names)
    if (idx_val is not None):
        assert (idx_val[0] in self.dtype.names)
    kpers = list(self.data.keys())
    kpers.sort()
    values = []
    for kper in range(0, max(self._model.nper, max(kpers))):
        if (kper < min(kpers)):
            values.append(0)
        elif ((kper > max(kpers)) or (kper not in kpers)):
            values.append(values[(- 1)])
        else:
            kper_data = self.__data[kper]
            if (idx_val is not None):
                kper_data = kper_data[np.where((kper_data[idx_val[0]] == idx_val[1]))]
            v = function(kper_data[attr])
            values.append(v)
    return values