Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Classe « Generator »

Méthode numpy.random.Generator.permuted

Signature de la méthode permuted

Description

permuted.__doc__

        permuted(x, axis=None, out=None)

        Randomly permute `x` along axis `axis`.

        Unlike `shuffle`, each slice along the given axis is shuffled
        independently of the others.

        Parameters
        ----------
        x : array_like, at least one-dimensional
            Array to be shuffled.
        axis : int, optional
            Slices of `x` in this axis are shuffled. Each slice
            is shuffled independently of the others.  If `axis` is
            None, the flattened array is shuffled.
        out : ndarray, optional
            If given, this is the destinaton of the shuffled array.
            If `out` is None, a shuffled copy of the array is returned.

        Returns
        -------
        ndarray
            If `out` is None, a shuffled copy of `x` is returned.
            Otherwise, the shuffled array is stored in `out`,
            and `out` is returned

        See Also
        --------
        shuffle
        permutation

        Examples
        --------
        Create a `numpy.random.Generator` instance:

        >>> rng = np.random.default_rng()

        Create a test array:

        >>> x = np.arange(24).reshape(3, 8)
        >>> 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]])

        Shuffle the rows of `x`:

        >>> y = rng.permuted(x, axis=1)
        >>> y
        array([[ 4,  3,  6,  7,  1,  2,  5,  0],  # random
               [15, 10, 14,  9, 12, 11,  8, 13],
               [17, 16, 20, 21, 18, 22, 23, 19]])

        `x` has not been modified:

        >>> 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]])

        To shuffle the rows of `x` in-place, pass `x` as the `out`
        parameter:

        >>> y = rng.permuted(x, axis=1, out=x)
        >>> x
        array([[ 3,  0,  4,  7,  1,  6,  2,  5],  # random
               [ 8, 14, 13,  9, 12, 11, 15, 10],
               [17, 18, 16, 22, 19, 23, 20, 21]])

        Note that when the ``out`` parameter is given, the return
        value is ``out``:

        >>> y is x
        True