Numpy shuffle & permutation random sequence

 

1. numpy.random.shuffle(x)

Modify a sequence in-place by shuffling its contents.

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 : array_like. The array or list to be shuffled.

Returns: None

note:

  • No return value, change the original array
  • For multi-dimensional array, the first dimension only shuffle

 

2. numpy.random.permutation(x) 

Randomly permute a sequence, or return a permuted range.

If x is a multi-dimensional array, it is only shuffled along its first index.

Parameters:	
x : int or array_like

If x is an integer, randomly permute np.arange(x). If x is an array, make a copy and shuffle the elements randomly.

Returns:	
out : ndarray

Permuted sequence or array range.

note:

  • With the difference shuffle
    • Return value
    • Does not change the original array, a new array will generate
  • x is an integer, x becomes the first array: np.arange (x), then scrambled

 

Guess you like

Origin www.cnblogs.com/dinghongkai/p/11422744.html