'Resize the matrix in-place to dimensions given by \'shape\'.
Any non-zero elements that lie outside the new shape are removed.'

def resize(self, shape):

    if (not isshape(shape)):
        raise TypeError('dimensions    must    be    a    2-tuple    of    positive    integers')
    (newM, newN) = shape
    (M, N) = self.shape
    if ((newM < M) or (newN < N)):
        for (i, j) in _list(self.keys()):
            if ((i >= newM) or (j >= newN)):
                del self[(i, j)]
    self._shape = shape
