'If key=(i,j) is a pair of integers, return the corresponding
element.  If either i or j is a slice or sequence, return a new sparse
matrix with just these elements.'

def __getitem__(self, index):

    zero = self.dtype.type(0)
    (i, j) = self._unpack_index(index)
    i_intlike = isintlike(i)
    j_intlike = isintlike(j)
    if (i_intlike and j_intlike):
        i = int(i)
        j = int(j)
        if (i < 0):
            i += self.shape[0]
        if ((i < 0) or (i >= self.shape[0])):
            raise IndexError('index    out    of    bounds')
        if (j < 0):
            j += self.shape[1]
        if ((j < 0) or (j >= self.shape[1])):
            raise IndexError('index    out    of    bounds')
        return dict.get(self, (i, j), zero)
    elif ((i_intlike or isinstance(i, slice)) and (j_intlike or isinstance(j, slice))):
        i_slice = (slice(i, (i + 1)) if i_intlike else i)
        j_slice = (slice(j, (j + 1)) if j_intlike else j)
        i_indices = i_slice.indices(self.shape[0])
        j_indices = j_slice.indices(self.shape[1])
        i_seq = xrange(*i_indices)
        j_seq = xrange(*j_indices)
        newshape = (len(i_seq), len(j_seq))
        newsize = _prod(newshape)
        if ((len(self) < (2 * newsize)) and (newsize != 0)):
            return self._getitem_ranges(i_indices, j_indices, newshape)
    (i, j) = self._index_to_arrays(i, j)
    if (i.size == 0):
        return dok_matrix(i.shape, dtype=self.dtype)
    min_i = i.min()
    if ((min_i < (- self.shape[0])) or (i.max() >= self.shape[0])):
        raise IndexError(('index    (%d)    out    of    range    -%d    to    %d)' % (i.min(), self.shape[0], (self.shape[0] - 1))))
    if (min_i < 0):
        i = i.copy()
        i[(i < 0)] += self.shape[0]
    min_j = j.min()
    if ((min_j < (- self.shape[1])) or (j.max() >= self.shape[1])):
        raise IndexError(('index    (%d)    out    of    range    -%d    to    %d)' % (j.min(), self.shape[1], (self.shape[1] - 1))))
    if (min_j < 0):
        j = j.copy()
        j[(j < 0)] += self.shape[1]
    newdok = dok_matrix(i.shape, dtype=self.dtype)
    for a in xrange(i.shape[0]):
        for b in xrange(i.shape[1]):
            v = dict.get(self, (i[(a, b)], j[(a, b)]), zero)
            if (v != 0):
                dict.__setitem__(newdok, (a, b), v)
    return newdok
