def part(x, *args):
n = len(args)<EOL>sl = slice(None)<EOL>if sps.issparse(x):<EOL><INDENT>if n == <NUM_LIT:1>: return x[args[<NUM_LIT:0>]]<EOL>elif n > <NUM_LIT:2>: raise ValueError('<STR_LIT>')<EOL>(ii,jj) = args<EOL>if   ii is Ellipsis: ii = sl<EOL>elif jj is Ellipsis: jj = sl<EOL>ni = pimms.is_number(ii)<EOL>nj = pimms.is_number(jj)<EOL>if   ni and nj: return x[ii,jj]<EOL>elif ni:        return x[ii,jj].toarray()[<NUM_LIT:0>]<EOL>elif nj:        return x[ii,jj].toarray()[:,<NUM_LIT:0>]<EOL>else:           return x[ii][:,jj]<EOL><DEDENT>else:<EOL><INDENT>x = np.asarray(x)<EOL>if n == <NUM_LIT:1>: return x[args[<NUM_LIT:0>]]<EOL>i0 = []<EOL>for (k,arg) in enumerate(args):<EOL><INDENT>if arg is Ellipsis:<EOL><INDENT>left = n - k - <NUM_LIT:1><EOL>i0 = [sl for _ in range(len(x.shape) - left)]<EOL><DEDENT>else:<EOL><INDENT>x = x[tuple(i0 + [arg])]<EOL>if not pimms.is_number(arg): i0.append(sl)<EOL><DEDENT><DEDENT>return x<EOL><DEDENT>
part(x, ii, jj...) is equivalent to x[ii, jj...] if x is a sparse matrix or numpy array and is
  equivalent to np.asarray(x)[ii][:, jj][...] if x is not. If only one argument is passed and
  it is a tuple, then it is passed like x[ii] alone.

The part function is comparible with slices (though the must be entered using the slice(...)
rather than the : syntax) and Ellipsis.