'Set diagonal or off-diagonal elements of the array.
Parameters
values : array_like
New values of the diagonal elements.
Values may have any length.  If the diagonal is longer than values,
then the remaining diagonal entries will not be set.  If values if
longer than the diagonal, then the remaining values are ignored.
If a scalar value is given, all of the diagonal is set to it.
k : int, optional
Which off-diagonal to set, corresponding to elements a[i,i+k].
Default: 0 (the main diagonal).'

def setdiag(self, values, k=0):

    (M, N) = self.shape
    if (((k > 0) and (k >= N)) or ((k < 0) and ((- k) >= M))):
        raise ValueError('k    exceeds    matrix    dimensions')
    self._setdiag(np.asarray(values), k)
