首页 > 其他 > 详细

Numpy 随机序列 shuffle & permutation

时间:2019-08-28 11:48:18      阅读:143      评论:0      收藏:0      [点我收藏+]

 

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

注意:

  • 无返回值,改变原有 array
  • 对于多维 array,只 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.

注意:

  • 跟 shuffle 的区别
    • 有返回值
    • 且不改变原来的 array,会生成一个新的 array
  • x 为整型时,先将 x 变成 array: np.arange(x),再打乱顺序

技术分享图片

 

Numpy 随机序列 shuffle & permutation

原文:https://www.cnblogs.com/dinghongkai/p/11422744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!