def fancy_transpose(data, roll=1):
    """Fancy transpose

    This method transposes a multidimensional matrix.

    Parameters
    ----------
    data : np.ndarray
        Input data array
    roll : int
        Roll direction and amount. Default (roll=1)

    Returns
    -------
    np.ndarray transposed data

    Notes
    -----
    Adjustment to numpy.transpose

    Examples
    --------
    >>> from modopt.base.np_adjust import fancy_transpose
    >>> x = np.arange(27).reshape(3, 3, 3)
    >>> x
    array([[[ 0,  1,  2],
            [ 3,  4,  5],
            [ 6,  7,  8]],
           [[ 9, 10, 11],
            [12, 13, 14],
            [15, 16, 17]],
           [[18, 19, 20],
            [21, 22, 23],
            [24, 25, 26]]])
    >>> fancy_transpose(x)
    array([[[ 0,  3,  6],
            [ 9, 12, 15],
            [18, 21, 24]],
           [[ 1,  4,  7],
            [10, 13, 16],
            [19, 22, 25]],
           [[ 2,  5,  8],
            [11, 14, 17],
            [20, 23, 26]]])
    >>> fancy_transpose(x, roll=-1)
    array([[[ 0,  9, 18],
            [ 1, 10, 19],
            [ 2, 11, 20]],
           [[ 3, 12, 21],
            [ 4, 13, 22],
            [ 5, 14, 23]],
           [[ 6, 15, 24],
            [ 7, 16, 25],
            [ 8, 17, 26]]])

    """

    axis_roll = np.roll(np.arange(data.ndim), roll)

    return np.transpose(data, axes=axis_roll)
def fancy_transpose ( data , roll = 1 ) : axis_roll = np . roll ( np . arange ( data . ndim ) , roll ) return np . transpose ( data , axes = axis_roll )
Fancy transpose

    This method transposes a multidimensional matrix.

    Parameters
    ----------
    data : np.ndarray
        Input data array
    roll : int
        Roll direction and amount. Default (roll=1)

    Returns
    -------
    np.ndarray transposed data

    Notes
    -----
    Adjustment to numpy.transpose

    Examples
    --------
    >>> from modopt.base.np_adjust import fancy_transpose
    >>> x = np.arange(27).reshape(3, 3, 3)
    >>> x
    array([[[ 0,  1,  2],
            [ 3,  4,  5],
            [ 6,  7,  8]],
           [[ 9, 10, 11],
            [12, 13, 14],
            [15, 16, 17]],
           [[18, 19, 20],
            [21, 22, 23],
            [24, 25, 26]]])
    >>> fancy_transpose(x)
    array([[[ 0,  3,  6],
            [ 9, 12, 15],
            [18, 21, 24]],
           [[ 1,  4,  7],
            [10, 13, 16],
            [19, 22, 25]],
           [[ 2,  5,  8],
            [11, 14, 17],
            [20, 23, 26]]])
    >>> fancy_transpose(x, roll=-1)
    array([[[ 0,  9, 18],
            [ 1, 10, 19],
            [ 2, 11, 20]],
           [[ 3, 12, 21],
            [ 4, 13, 22],
            [ 5, 14, 23]],
           [[ 6, 15, 24],
            [ 7, 16, 25],
            [ 8, 17, 26]]])