def resize(self, shape):
if not isshape(shape):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>newM, newN = shape<EOL>M, N = self.shape<EOL>if newM < M or newN < N:<EOL><INDENT>for (i, j) in list(self.keys()):<EOL><INDENT>if i >= newM or j >= newN:<EOL><INDENT>del self[i, j]<EOL><DEDENT><DEDENT><DEDENT>self._shape = shape<EOL>
Resize the matrix in-place to dimensions given by 'shape'.

        Any non-zero elements that lie outside the new shape are removed.