This is a pre-release version (2.5.0.dev0+git20251130.2de293a).Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / random / RandomState / shuffle

cython_function_or_method

numpy.random:RandomState.shuffle

Signature

def shuffle(x)

Summary

Modify a sequence in-place by shuffling its contents.

Extended Summary

This function only shuffles the array along the first axis of a multi-dimensional array. 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.

Returns

: None

Examples

arr = np.arange(10)
np.random.shuffle(arr)
✓
arr
✗
array([9, 4, 8, 5, 6, 3, 7, 0, 2, 1])
Multi-dimensional arrays are only shuffled along the first axis:
arr = np.arange(9).reshape((3, 3))
np.random.shuffle(arr)
✓
arr
✗
array([[3, 4, 5],
       [0, 1, 2],
       [6, 7, 8]])

See also

random.Generator.shuffle

which should be used for new code.

Aliases

  • numpy.random.shuffle
  • numpy.random.RandomState.shuffle