'Permute the rows or columns of a matrix by the given list of swaps.
Parameters
perm : a permutation.  This may be a list swaps (e.g., `[[1, 2], [0, 3]]`),
or any valid input to the `Permutation` constructor, including a `Permutation()`
itself.  If `perm` is given explicitly as a list of indices or a `Permutation`,
`direction` has no effect.
orientation : (\'rows\' or \'cols\') whether to permute the rows or the columns
direction : (\'forward\', \'backward\') whether to apply the permutations from
the start of the list first, or from the back of the list first
Examples
>>> from sympy.matrices import eye
>>> M = eye(3)
>>> M.permute([[0, 1], [0, 2]], orientation=\'rows\', direction=\'forward\')
Matrix([
[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
>>> from sympy.matrices import eye
>>> M = eye(3)
>>> M.permute([[0, 1], [0, 2]], orientation=\'rows\', direction=\'backward\')
Matrix([
[0, 1, 0],
[0, 0, 1],
[1, 0, 0]])'

def permute(self, perm, orientation='rows', direction='forward'):

    if (direction == 'forwards'):
        direction = 'forward'
    if (direction == 'backwards'):
        direction = 'backward'
    if (orientation == 'columns'):
        orientation = 'cols'
    if (direction not in ('forward', 'backward')):
        raise TypeError("direction='{}'    is    an    invalid    kwarg.    Try    'forward'    or    'backward'".format(direction))
    if (orientation not in ('rows', 'cols')):
        raise TypeError("orientation='{}'    is    an    invalid    kwarg.    Try    'rows'    or    'cols'".format(orientation))
    max_index = (self.rows if (orientation == 'rows') else self.cols)
    if (not all(((0 <= t <= max_index) for t in flatten(list(perm))))):
        raise IndexError('`swap`    indices    out    of    range.')
    try:
        assert (len(perm[0]) == 2)
        if (direction == 'backward'):
            perm = reversed(perm)
        mapping = list(range(max_index))
        for (i, j) in perm:
            (mapping[i], mapping[j]) = (mapping[j], mapping[i])
        perm = mapping
    except (TypeError, AssertionError, IndexError):
        pass
    from sympy.combinatorics import Permutation
    perm = Permutation(perm, size=max_index)
    if (orientation == 'rows'):
        return self._eval_permute_rows(perm)
    if (orientation == 'cols'):
        return self._eval_permute_cols(perm)
