You are viewing an older version (2.4.3).Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / random / _generator / Generator / shuffle

cython_function_or_method

numpy.random._generator:Generator.shuffle

Signature

def shuffle(x, axis = 0)

Summary

Modify an array or sequence in-place by shuffling its contents.

Extended Summary

The order of sub-arrays is changed but their contents remains the same.

Parameters

x : ndarray or MutableSequence

The array, list or mutable sequence to be shuffled.

axis : int, optional

The axis which x is shuffled along. Default is 0. It is only supported on ndarray objects.

Returns

: None

Notes

An important distinction between methods shuffle and permuted is how they both treat the axis parameter which can be found at generator-handling-axis-parameter.

Examples

rng = np.random.default_rng()
arr = np.arange(10)
arr
rng.shuffle(arr)
✓
arr
✗
array([5, 8, 2, 0, 3, 9, 6, 4, 7, 1])
arr = np.arange(9).reshape((3, 3))
arr
rng.shuffle(arr)
✓
arr
✗
array([[6, 7, 8],
       [3, 4, 5],
       [0, 1, 2]])
arr = np.arange(9).reshape((3, 3))
arr
rng.shuffle(arr, axis=1)
✓
arr
✗
array([[1, 2, 0],
       [4, 5, 3],
       [7, 8, 6]])

See also

permutation
permuted

Aliases

  • numpy.random.Generator.shuffle

Referenced by